Andrew (Digitwell) Well-Known Member Licensed User Longtime User Nov 3, 2020 #1 In iOS the following code returns a string containing "1000", in Android the code returns a string, containing "1000.0" I think that this is a bug. B4X: Private n As Double = 1000 private s as string = NumberFormat2(n,0,2,0,False) log(s)
In iOS the following code returns a string containing "1000", in Android the code returns a string, containing "1000.0" I think that this is a bug. B4X: Private n As Double = 1000 private s as string = NumberFormat2(n,0,2,0,False) log(s)
E emexes Expert Licensed User Longtime User Nov 3, 2020 #3 Andrew (Digitwell) said: In iOS the following code returns a string containing "1000", in Android the code returns a string, containing "1000.0" I think that this is a bug. B4X: Private n As Double = 1000 private s as string = NumberFormat2(n,0,2,0,False) log(s) Click to expand... iOS looks correct. Minimum decimal fraction places is 0. Perhaps Android is splitting the difference, and giving you the average of 0 and 2 decimal fraction places.
Andrew (Digitwell) said: In iOS the following code returns a string containing "1000", in Android the code returns a string, containing "1000.0" I think that this is a bug. B4X: Private n As Double = 1000 private s as string = NumberFormat2(n,0,2,0,False) log(s) Click to expand... iOS looks correct. Minimum decimal fraction places is 0. Perhaps Android is splitting the difference, and giving you the average of 0 and 2 decimal fraction places.
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Nov 3, 2020 #4 @emexes Yes, iOS is correct. @klaus, I am running OpenJdk 11.0.1. Is that the same as you? I wonder if it is some strange precision problem. I only noticied it because, I put this post up, https://www.b4x.com/android/forum/t...credit-card-and-apple-pay.124141/#post-775333, and it wasn't working on Android as STRIPE was rejecting the "1000.0" as the number. In the end, I just frigged it by adding: B4X: else If checkfornumber(o) Then #if B4a Private n As Int = o #else if B4I Private n As Double = o #End If s = s & prevprefix & su.EncodeUrl(actprefix & "["&ky & "]","UTF8")&"="& NumberFormat2(n,0,0,0,False) Else in the function convertsubmaptoUrlEncode in StripeClass
@emexes Yes, iOS is correct. @klaus, I am running OpenJdk 11.0.1. Is that the same as you? I wonder if it is some strange precision problem. I only noticied it because, I put this post up, https://www.b4x.com/android/forum/t...credit-card-and-apple-pay.124141/#post-775333, and it wasn't working on Android as STRIPE was rejecting the "1000.0" as the number. In the end, I just frigged it by adding: B4X: else If checkfornumber(o) Then #if B4a Private n As Int = o #else if B4I Private n As Double = o #End If s = s & prevprefix & su.EncodeUrl(actprefix & "["&ky & "]","UTF8")&"="& NumberFormat2(n,0,0,0,False) Else in the function convertsubmaptoUrlEncode in StripeClass
Erel B4X founder Staff member Licensed User Longtime User Nov 3, 2020 #5 The java version isn't relevant. This is not a bug as 1000.0 meets the set minimum and maximum values. Best to use B4XFormatter. It will work exactly the same in all platforms: Code: Dim f As B4XFormatter f.Initialize f.GetDefaultFormat.MaximumFractions = 2 f.GetDefaultFormat.MinimumFractions = 0 f.GetDefaultFormat.GroupingCharacter = "" Log(f.Format(n))
The java version isn't relevant. This is not a bug as 1000.0 meets the set minimum and maximum values. Best to use B4XFormatter. It will work exactly the same in all platforms: Code: Dim f As B4XFormatter f.Initialize f.GetDefaultFormat.MaximumFractions = 2 f.GetDefaultFormat.MinimumFractions = 0 f.GetDefaultFormat.GroupingCharacter = "" Log(f.Format(n))
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Nov 3, 2020 #6 I didn't realise that Numberformat2 could do that. I assumed that it would give the minimum possible format. I tend to use Numberformat2 quite a lot so I will write a little function to take the same parameters and call B4XFormatter instead.
I didn't realise that Numberformat2 could do that. I assumed that it would give the minimum possible format. I tend to use Numberformat2 quite a lot so I will write a little function to take the same parameters and call B4XFormatter instead.
klaus Expert Licensed User Longtime User Nov 3, 2020 #7 Erel said: This is not a bug as 1000.0 meets the set minimum and maximum values. Click to expand... I would expect, that for 1000 with MiniumFraction = 0, the result beeing 1000 and not 1000.0. And why not 1000.00 which respects also the requirements? Andrew (Digitwell) said: I am running OpenJdk 11.0.1. Is that the same as you? Click to expand... I use Java 11.0.1 too.
Erel said: This is not a bug as 1000.0 meets the set minimum and maximum values. Click to expand... I would expect, that for 1000 with MiniumFraction = 0, the result beeing 1000 and not 1000.0. And why not 1000.00 which respects also the requirements? Andrew (Digitwell) said: I am running OpenJdk 11.0.1. Is that the same as you? Click to expand... I use Java 11.0.1 too.
Erel B4X founder Staff member Licensed User Longtime User Nov 3, 2020 #8 klaus said: I would expect, that for 1000 with MiniumFraction = 0, the result beeing 1000 and not 1000.0. And why not 1000.00 which respects also the requirements? Click to expand... This happens in the native API. I guess that the default string representation of 1000 is 1000.0 and it doesn't modify it if it meets the requirements.
klaus said: I would expect, that for 1000 with MiniumFraction = 0, the result beeing 1000 and not 1000.0. And why not 1000.00 which respects also the requirements? Click to expand... This happens in the native API. I guess that the default string representation of 1000 is 1000.0 and it doesn't modify it if it meets the requirements.
klaus Expert Licensed User Longtime User Nov 3, 2020 #9 Anyway, as written in post #2, on my device it displays OK. I tested with n = 1000.001 and the display is 1000, as expected by me. So am astonished that it is wrong for Andrew.
Anyway, as written in post #2, on my device it displays OK. I tested with n = 1000.001 and the display is 1000, as expected by me. So am astonished that it is wrong for Andrew.
E emexes Expert Licensed User Longtime User Nov 3, 2020 #10 Erel said: This is not a bug as 1000.0 meets the set minimum and maximum values. Click to expand... emexes said: giving you the average of 0 and 2 decimal fraction places. Click to expand... I can't fault your explanation but I like mine better. ☮
Erel said: This is not a bug as 1000.0 meets the set minimum and maximum values. Click to expand... emexes said: giving you the average of 0 and 2 decimal fraction places. Click to expand... I can't fault your explanation but I like mine better. ☮