Edit: changed fiat to textFiat in expected & actual to make it clearer that its not expected to format the original var but the output of numberforma to a text obj
@ggpanta
NumberFormat(fiat, 0, 2) does not round the number it returns a string that is used for display.
If you want to round the number you'd use Round2(Number As Double, DecimalPlaces As Int).
@LucaMs unfortunatelly I cant make it work for some reason
@klaus thats what I am rounding in my code a string and for some reason it doesnt work... textfield1= NumberFormat(fiat, 0, 2) should have only 2 decimals but I am not seeing that
I will have to look at the code maybe I am doing something wrong that I am not seeing.
I dont want rounding to happen at all though, I need the extra decimals for calculations but I only want to show 2 decimals in the string. This is a cryptocurrency app and decimals are very important, even 0.0000001 of a coin has actual monetary value, so the decimals must stay as they are, what I show to the user in some parts (summary) just doesnt need them, I am cutting the string now so its ok but for some reason numberformat doesnt want to play.
JSON.Initialize(APIReply)
Dim mapAPI As Map
mapAPI = JSON.NextObject
Dim fiat As Double
fiat = mapAPI.Get("last")
lblExchangeValue.Text = NumberFormat(fiat, 0, 2)
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim fiat As Double
fiat = 6368.4397
Log("With decimal values not=zero: " & NumberFormat(fiat, 0, 2))
fiat = 6368.0 '4397
Log("With decimal value of zero: " & NumberFormat(fiat, 0, 2))
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
RESULTS:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
With decimal values not=zero: 6,368.44
With decimal value of zero: 6,368
** Activity (main) Resume **
What exactly do you expect ? NumberFormat(Number As Double, MinimumIntegers As Int, MaximumFractions As Int)
returns 2 fractions max but removes any non significant zeros.
If you want at least one fraction you should use NumberFormat2: NumberFormat2(Number As Double, MinimumIntegers As Int, MaximumFractions As Int, MinimumFractions As Int, GroupingUsed As Boolean)