How to use float value in Spinbox without comma separator?
Solved
QML and Qt Quick
-
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) } }
-
@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) }
-