Android Question Rouns2 Question

grant1842

Active Member
Licensed User
I am doing some math.

B4X:
Sub btCalc_Click
  
    '468= half wavelength
    '234 quarter wave length
  
    Dim  num1 = 234 As Float  'wavelength
    Dim  num2 = 7.200 As Float 'frequency
  
    Result = num1 / num2 '32.5
    Result2 = Result * 10 '3.25
    sum = (Result2 + Result)
    edResult.Text= Round2(sum,2)
  
End Sub
The sum = 357.5
I need to format the sum to look like 35.75
Thanks for your help.
 

HotShoe

Well-Known Member
Licensed User
Why do you multiply Result by 10? that makes it 325 instead of 32.5. Maybe you meant to divide by 10?

--- Jem
 

grant1842

Active Member
Licensed User
The multiply is correct . I just need to round the sum to display correctly.
Thanks for your comment
 

HotShoe

Well-Known Member
Licensed User
Then you'd need to multiply by .10

Round2 won't help with converting a number, only with the number of decimal places to display.

--- Jem
 

klaus

Expert
Licensed User
Looking at your code
Result2 = Result * 10 '3.25 ???
as HotShoe said, you need to divide by 10.
To display the sum correctly use:
B4X:
edResult.Text= NumberFormat(sum, 1, 2)
 
Top