Android Question Rounding ?

derez

Expert
Licensed User
Longtime User
What you get is
-1.8369701987210297E-16
Which is very very small. Round it using numberformat and you'll have 0.
 
Upvote 0

syncmaster13

Member
Licensed User
Longtime User
I tough problem is solved but in some cases using Round2 or NumberFormat2 shows 4 decimal places but instead of "0" i get "-5.0E-4)
Please, show me what I'm doing wrong.


Sub Process_Globals

End Sub

Sub Globals
Dim X As Double
Dim Y As Double
Dim N As Int = 14
Dim B As Double = Round2((360/N),2)
Dim R As Double = 0.5

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")

X = Round2((CosD(N * B) * R),4)

Y = Round2((SinD(N * B) * R),4)

Msgbox(Y, "4 decimal places? ")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Using this Dim B As Double = Round2((360/N),2) you created a large error because you rounded to 2 .
If you round it to 4 you'll probably get 0 or 1 for sind and cosd.
Why do you round it at all ? do you display B ?
 
Upvote 0

syncmaster13

Member
Licensed User
Longtime User
In this example i don't, but I'n my project there is a loop with x,y, and incremental B angle.
I removed round2 from B and used it only for display and it works. I'm really surprised what mistake I made.

Thank you
 
Upvote 0
Top