Home > Mobile >  How can I display a number in QML with its sign, even if it is ?
How can I display a number in QML with its sign, even if it is ?

Time:07-26

//I know this code does the job for positive numbers but not for all numbers.

text: qsTr (" ") (some_positive_number)

//Is there a way that I can always display any number with its sign beside it?

CodePudding user response:

This should work fine in standard javascript:

(a - b > 0 ? " " : "")   (a - b)

Note that:

  1. There is little to no sense in using qsTr for since its meaning is fairly localised and internationalised by default.

  2. No need to calculate the difference of a - b thrice.

CodePudding user response:

text: (a - b > 0) ? (qsTr(" ") (a - b)) : (a - b)

//This will work fine.

  • Related