October 28, 2020, 11:09:38 PM

Author Topic: rounds a float value to 0.001 or more else it becomes 0  (Read 695 times)

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1065
rounds a float value to 0.001 or more else it becomes 0
« 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
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1121
Re: rounds a float value to 0.001 or more else it becomes 0
« Reply #1 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