Hey noisetank,
Lets assume our number is stored in a variable named "num", and we want to format it as an integer part, always followed by two decimal digits, even when either or both are zeros.
There are a few ways to go about this.
The method I'm showing below converts the number to text and then inserts a "." into the correct spot.
We create a text variable named "digits".
digits = zeropad( round( num * 100 ) , ( 2 + 1 ) )
Formated string = left( digits , ( len( digits ) - 2 ) ) & "." & right( digits , 2 )
Done.
To make it clearer what is going on in the above steps, I've created two examples below that show the evaluation of the expressions from beginning to end, so you can see how each part of the expression works.
Example #1
If num = 888.123
digits = zeropad( round( 888.123 * 100 ) , ( 2 + 1 ) )
digits = zeropad( round( 88812.3 ) , ( 2 + 1 ) )
digits = zeropad( 88812 , ( 2 + 1 ) )
digits = "88812"
Formated string = left( "88812" , ( len( "88812" ) - 2 ) ) & "." & right( "88812" , 2 )
Formated string = left( "88812" , ( len( "88812" ) - 2 ) ) & "." & "12"
Formated string = left( "88812" , ( len( "88812" ) - 2 ) ) & "." & "12"
Formated string = left( "88812" , ( 5 - 2 ) ) & "." & "12"
Formated string = left( "88812" , 3 ) & "." & "12"
Formated string = "888" & "." & "12"
Formated string = "888.12"
Example #2
If num = 0.071
digits = zeropad( round( 0.071 * 100 ) , ( 2 + 1 ) )
digits = zeropad( round( 7.1 ) , ( 2 + 1 ) )
digits = zeropad( 7 , ( 2 + 1 ) ) // This zero pad makes sure we have at least 1 digit in the 1's place, even if it's a "0".
digits = "007"
Formated string = left( "007" , ( len( "007" ) - 2 ) ) & "." & right( "007" , 2 )
Formated string = "0" & "." & "07"
Formated string = "0.07"
Hope that helps.