B4J Question NumberFormat issue or BUG?

Cableguy

Expert
Licensed User
Longtime User
I have the following code:

mValue = NumberFormat2(TextField1.Text + StepValue, 1, mDecimals, mDecimals, False)

where mValue is Double, StepValue and mDecimals are integers defined in the designer...

Given a mDecimals of value 2, shouldn't this code convert a number like 1.1 to a string like "1.10"??

I ask because all I get is the same decimal places as the mathematical value (i.e 1 + 0.1 = 1.1) , no mater how I format the number


[EDIT]

Seems like using NumberFormat on a variable has a different behaviour than using it directly on a string like a TextField.text, where it works perfect
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
B4X:
    Log(NumberFormat2(1.1,1,2,2,False)) ' Logs 1.10

Edit: ok, i tried this with B4A.

I would guess a bug in B4J
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
see my Edit
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
NumberFormat returns a String !
But your variable is a Double, the only thing you may achieve is a sort of rounding, but not a display formating.
To format a number for display you must use a String variable as the return variable and not a Double.
 
Upvote 0
Top