SyntaxBomb - Indie Coders

Languages & Coding => Blitz Code Archives => Miscellaneous => Topic started by: RemiD on October 19, 2019, 05:24:00 PM

Title: rounds a float value to 0.001 or more else it becomes 0
Post by: RemiD on October 19, 2019, 05:24:00 PM
Code: [Select]
;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
Title: Re: rounds a float value to 0.001 or more else it becomes 0
Post by: 3DzForMe on October 19, 2019, 07:49:50 PM
I can't believe this RemiD - I was pondering this very issue this afternoon when invoking some joypad stuff (to prevent two peeps crowding around a keyboard....." :o
SimplePortal 2.3.6 © 2008-2014, SimplePortal