rounds a float value to 0.001 or more else it becomes 0
Attention! 👉Starting November 2024, BlitzCoder.org will now be BlitzBasic.org.
Tweet blitz3d code-archives miscellaneous
the goal of this procedure is to get rid of all float values less than 0.001 so the e-004 or similar writing does not appear anymore which may cause errors in your code...
;rounds a float value to 0.001 or more else it becomes 0
;when you type/get 0.001, it stays 0.001, but when you type/get 0.0001 it becomes "1.0e-004"
;when you type/get "1.0e-004" it stays "1.0e-004", "but when you type 1.0e-003" it becomes 0.001
;the goal of this procedure is to get rid of all float values less than 0.001 so the e-004 or similar writing does not appear anymore which may cause errors in your code...
Graphics(854,480,32,2)
For i% = 1 To 100 Step 1
F# = Rnd(0.0001,0.009) ;try with values between 0.0001 and 0.009, only the values of 0.001 or more should be kept
RF# = RoundFloat(F)
DebugLog(F+"->"+RF)
Next
WaitKey()
End()
Function RoundFloat#(F#)
FInt% = Int(F*1000)
FRounded# = Float(FInt)/1000
Return FRounded
End Function
Thanks for sharing RemiD. I see you already have added it with tags. You can also check the code markup for the code formatting.
Reply To Topic (minimum 10 characters)
Please log in to reply