Android Question B4X Formatter question

stanks

Active Member
Licensed User
Longtime User
Hi

I have double like 6.123456
Next part of code always returns 3 fractions.
B4X:
Dim ff As B4XFormatter
ff.Initialize
Dim DefaultFormat As B4XFormatData = ff.GetDefaultFormat
DefaultFormat.MaximumFractions = 6
DefaultFormat.MinimumFractions = 2
Dim kzd_s As String = ff.Format(kzd)

What i am doing wrong?

Thanks
 

emexes

Expert
Licensed User
Or if you want 3 fractions (aka decimal places?) then... ask, and ye shall receive:
B4X:
Dim ff As B4XFormatter
ff.Initialize
Dim DefaultFormat As B4XFormatData = ff.GetDefaultFormat
DefaultFormat.MaximumFractions = 3
DefaultFormat.MinimumFractions = 3
Dim kzd_s As String = ff.Format(6.123456)
Log(kzd_s)
The output is: 6.123
 
Upvote 0

emexes

Expert
Licensed User
Your original code would give you between 2 and 6 decimal places, eg:
B4X:
ff.Format(6.1)        returns "6.10"       'min 2 dp
ff.Format(6.12)       returns "6.12"       '2 dp
ff.Format(6.123)      returns "6.123"
ff.Format(6.1234)     returns "6.1234"
ff.Format(6.12345)    returns "6.12345"
ff.Format(6.123456)   returns "6.123456"   '6 dp
ff.Format(6.1234567)  returns "6.123457"   'max 6 dp, last digit rounded (here: up)
ff.Format(6.12345678) returns "6.123457"   'ditto
 
Upvote 0
Top