Android Question problem with NumberFormat with Android 11

Lello1964

Well-Known Member
Licensed User
Longtime User
I have foud this difference between Android 9 and Android 11

I have this code
B4X:
Dim a As Int =0
Log(NumberFormat(a,0,4) )

Android 9 :
result = 0

Android 11 :
result = .0

why there is . before 0 ?
Someone have some problem, how solve ?

other example
B4X:
Dim a As Int =12
Log(NumberFormat(a,0,4) )

Android 9 :
result = 12

Android 11 :
result = 12.0
 
Last edited:
D

Deleted member 103

Guest
I also have this mistake in earlier versions when I remember correctly.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
isn't a solution

but if i have 12.546

result is 12 but it must be 12.546

What, 12.546 is a decimal and not an integer, what are you talking about???????

Make your mind up will you, you wrote
B4X:
Dim a As Int =12

Can you see where you wrote Int, how are you seriously expecting to get 12.546 ???
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
sorry. but the problem isn't solved

Dim b As Double =12.546
Log(NumberFormat(b,0,0))
Log(NumberFormat2(b,0,0,0,True))

result :

12
13

doesn't solve my problem.
 
Upvote 0

DataMiser

Member
Licensed User
you are passing 0 for the min and max decimal places so of course you get nothing after the decimal.
If you want a max of 3 decimal places then you need to place a 3 in that parameter.
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
Why difference between Android <11 and android 11 result ?
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
B4X:
Dim a As Int =0
Log(NumberFormat(a,0,4))

result :

in Andoid9 : 0
in Android10 : .0

This isn't same.
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
This is only an example
Why are you setting the minimum integers parameter to 0? If you want it to be 1 then set it to 1. It is really simple.
The results meet your settings.
this is just one example.
The difference also occurs with other numbers and formats.
Having to convert the numeric format into Italian, this generates errors in the app. changing the function in NumberFormat2 all the representations of the numbers change, compromising the graphic result.
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
@Star-Dust tell me a solution.
But i must rmodify all my Apps.

B4X:
Public Sub NumberFormatPlus(Number As Double, MinimumIntegers As Int, MaximumFractions As Int) As String
    If Number=Round(Number) Then
        Return $"$1.0{Number}"$
    Else
        Return NumberFormat(Number,MinimumIntegers,MaximumFractions)
    End If
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is equivalent to:
B4X:
If Number=Round(Number) Then
        Return NumberFormat(Number, 1, 0)
    Else
        Return NumberFormat(Number,MinimumIntegers,MaximumFractions)
    End If

I don't know what you are trying to do but will probably be safer to do something like:
B4X:
If Abs(Number - Round(Number)) < 0.00000001 Then
  Return NumberFormat(Number, 1, 0)
    Else
        Return NumberFormat(Number,MinimumIntegers,MaximumFractions)
    End If
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
Thanks @Erel, i'll use your solution, but why this difference between Andorid 9 and Android 11?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Would solve the problem by simply setting the number of digits of integers to 1 rather than 0.

Setting it to 0 Android 11 when there are no integers does not even display zero, and it seems to me a correct behavior while previous versions when there are no digits integers displays zero
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Or Alternative
B4X:
Public Sub NumberFormatPlus(Number As Double, MinimumIntegers As Int, MaximumFractions As Int) As String
      Return NumberFormat(Number,Max(MinimumIntegers,1),MaximumFractions)
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…