Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to use float value in Spinbox without comma separator?

How to use float value in Spinbox without comma separator?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 472 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    ynatynat
    wrote on 26 Jul 2023, 02:37 last edited by
    #1

    How to use float value in Spinbox without comma separator?
    I would like to show 2000.25, but below shows 2,000.25.

        SpinBox{
            id:spin
            width:valuebox_wrapper.width*0.35
            height:btn_calltenkey.height
            value: 2000.25
            property int decimals :2;
            from:min*Math.pow(10, decimals)
            to:max*Math.pow(10, decimals)
    
            validator: DoubleValidator {
                bottom: Math.min(spin.from, spin.to)
                top:  Math.max(spin.from, spin.to)
            }
    
            textFromValue: function(value, locale) {
                return Number(value / Math.pow(10, decimals)).toLocaleString(locale, 'f', decimals)//<-----shows 2,000.25
            }
    
            valueFromText: function(text, locale) {
                return Number.fromLocaleString(locale, text) * Math.pow(10, decimals)
            }
    
    
        }
    
    M 1 Reply Last reply 26 Jul 2023, 04:39
    0
    • Y ynatynat
      26 Jul 2023, 02:37

      How to use float value in Spinbox without comma separator?
      I would like to show 2000.25, but below shows 2,000.25.

          SpinBox{
              id:spin
              width:valuebox_wrapper.width*0.35
              height:btn_calltenkey.height
              value: 2000.25
              property int decimals :2;
              from:min*Math.pow(10, decimals)
              to:max*Math.pow(10, decimals)
      
              validator: DoubleValidator {
                  bottom: Math.min(spin.from, spin.to)
                  top:  Math.max(spin.from, spin.to)
              }
      
              textFromValue: function(value, locale) {
                  return Number(value / Math.pow(10, decimals)).toLocaleString(locale, 'f', decimals)//<-----shows 2,000.25
              }
      
              valueFromText: function(text, locale) {
                  return Number.fromLocaleString(locale, text) * Math.pow(10, decimals)
              }
      
      
          }
      
      M Offline
      M Offline
      Markkyboy
      wrote on 26 Jul 2023, 04:39 last edited by
      #2

      @ynatynat - maybe this helps, but looking at your code, it seems you have more or less done this;

      https://stackoverflow.com/questions/45679316/qt-qml-quick-control-2-spinbox-value-without-number-format

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      Y 1 Reply Last reply 26 Jul 2023, 08:53
      0
      • M Markkyboy
        26 Jul 2023, 04:39

        @ynatynat - maybe this helps, but looking at your code, it seems you have more or less done this;

        https://stackoverflow.com/questions/45679316/qt-qml-quick-control-2-spinbox-value-without-number-format

        Y Offline
        Y Offline
        ynatynat
        wrote on 26 Jul 2023, 08:53 last edited by
        #3

        @Markkyboy
        Thank you for reply.
        I found how to do.

                textFromValue: function(value, locale) {
                    //return Number(value / Math.pow(10, decimals)).toLocaleString(locale, 'f', decimals)//<-----shows 2,000.25
        
                    let num = Number(value / Math.pow(10, decimals))
                    return Number.parseFloat(num).toFixed(decimals)
                }
        
                valueFromText: function(text, locale) {
                    //return Number.fromLocaleString(locale, text) * Math.pow(10, decimals)
                    return Number.parseFloat(text) * Math.pow(10, decimals)
                }
        
        1 Reply Last reply
        0
        • Y ynatynat has marked this topic as solved on 27 Jul 2023, 09:35

        2/3

        26 Jul 2023, 04:39

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved