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?
QtWS25 Last Chance

How to use float value in Spinbox without comma separator?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 461 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 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)
            }
    
    
        }
    
    MarkkyboyM 1 Reply Last reply
    0
    • Y ynatynat

      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)
              }
      
      
          }
      
      MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on 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
      0
      • MarkkyboyM Markkyboy

        @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 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

        • Login

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