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:
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
I also have this mistake in earlier versions when I remember correctly.
 
Upvote 0
Log(NumberFormat(a, 0, 0))
Log(NumberFormat2(a, 0, 0, 0, False))
 
Upvote 0
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
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
Please use [code]code here...[/code] tags when posting code.

I don't see any unexpected result in this thread.
I think that tou are looking for:
Code:
NumberFormat2(b,1,3,0,True)
Why difference between Android <11 and android 11 result ?
 
Upvote 0
B4X:
Dim a As Int =0
Log(NumberFormat(a,0,4))

result :

in Andoid9 : 0
in Android10 : .0

This isn't same.
 
Upvote 0
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
@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
It is equivalent to:
Code:
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:
Code:
If Abs(Number - Round(Number)) < 0.00000001 Then
  Return NumberFormat(Number, 1, 0)
    Else
        Return NumberFormat(Number,MinimumIntegers,MaximumFractions)
    End If
 
Upvote 0
It is equivalent to:
Code:
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:
Code:
If Abs(Number - Round(Number)) < 0.00000001 Then
  Return NumberFormat(Number, 1, 0)
    Else
        Return NumberFormat(Number,MinimumIntegers,MaximumFractions)
    End If
Thanks @Erel, i'll use your solution, but why this difference between Andorid 9 and Android 11?
 
Upvote 0
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
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
Back
Top