Android Question Big Decimal Rounding Question

WDK

Member
Licensed User
I am using SetScale2 for my rounding. It is working great, except want to strip decimal places if they are zero. I am allowing for up to 10 decimal places.

BG_CalculateFormula.SetScale2(10, BG_CalculateFormula.ROUND_HALF_UP)

Example:

Currently: 40468564.2240000000
Would like: 40468564.224 (stripping off 0s)

If I have: 40468564.2240000001
I would still like to have: 40468564.2240000001 (this is working as expected)

Thanks for any help!
WDK
 

OliverA

Expert
Licensed User
Longtime User
Maybe:
B4X:
Dim stripped As String
stripped = BG_CalculateFormula.ToString
Dim m As Matcher
m = Regex.Matcher("(.+?)(0+)$",stripped)
If m.Find Then
    stripped = m.Group(1)
End If
Log(stripped)
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
Can you simply add zero?
Something like
B4X:
yourvar = yourvar + 0
That should recalc and drop off the trailing zeroes.
 
Upvote 0
Top