Android Question BigNumber syntax. [Answered]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I have a number of existing "formulae" that need to be rewritten using BigNumbers but I am not sure of the best way to use BN. Below is a quick example of what exists. When I started to rewrite it I quickly created something very messy. Could someone please use this example of this using BN. I believe I will then be able to work out the rest.

B4X:
Private R1, r2 as String
Private  PCent as Double

Sub PC
    PCent = R1 * (1 + (r2 / 100))
End Sub

Thanks in advance
Roger
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why do you use global variables?

B4X:
   R1 = WrapNumber(23)
   r2 = WrapNumber(1000)
   Log(PC)


Sub PC As BigDecimal
   PCent.Initialize3(0)
   Return PCent.Add(r2).Divide(WrapNumber(100)).Add(WrapNumber(1)).Multiply(R1)   
End Sub

Sub WrapNumber (d As Double) As BigDecimal
   Dim b As BigDecimal
   b.Initialize(d)
   Return b
End Sub
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Why do you use global variables?

B4X:
   R1 = WrapNumber(23)
   r2 = WrapNumber(1000)
   Log(PC)


Sub PC As BigDecimal
   PCent.Initialize3(0)
   Return PCent.Add(r2).Divide(WrapNumber(100)).Add(WrapNumber(1)).Multiply(R1) 
End Sub

Sub WrapNumber (d As Double) As BigDecimal
   Dim b As BigDecimal
   b.Initialize(d)
   Return b
End Sub
Thanks Erel
 
Upvote 0
Top