AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Floats and Decimal Rounding (https://forums.alliedmods.net/showthread.php?t=47072)

Politics 11-09-2006 05:14

Floats and Decimal Rounding
 
I have a float being called from a SQL row which has the value of 5.05 but it is apparently 5.0499999 when it is stored in the float I have made. How can I make it so that is stored as 5.05 not 5.0499999.

Greenberet 11-09-2006 05:15

Re: Floats and Decimal Rounding
 
http://forums.alliedmods.net/showthr...288#post401288

The Specialist 11-09-2006 05:22

Re: Floats and Decimal Rounding
 
hmmm , flaot round will round the flaot off to an interger value . but in order todo what you want im not sure what you would do . except maybee re-assig the flaot the real value you wanted .
4.049 = 4.05 ??? or something like that :wink:

Politics 11-09-2006 05:25

Re: Floats and Decimal Rounding
 
Quote:

Originally Posted by Greenberet (Post 401389)

Still gives many trailing 0's or not the exact number

Quote:

Originally Posted by The Specialist (Post 401391)
hmmm , flaot round will round the flaot off to an interger value . but in order todo what you want im not sure what you would do . except maybee re-assig the flaot the real value you wanted .
4.049 = 4.05 ??? or something like that :wink:

I would use floatround if I wanted an integer but I want to try to keep it a float. I'm not too sure either.

The Specialist 11-09-2006 06:11

Re: Floats and Decimal Rounding
 
so i guess like a said the other option is assignment.
Code:
  new Flaot: 5.0499999 = 5.05
that would assign the flaot 5.049 to 5.05 from now on , re-inforcing the value you wanted it to have . :up:

Zenith77 11-09-2006 08:24

Re: Floats and Decimal Rounding
 
Quote:

Originally Posted by The Specialist (Post 401397)
so i guess like a said the other option is assignment.
Code:
  new Flaot: 5.0499999 = 5.05
that would assign the flaot 5.049 to 5.05 from now on , re-inforcing the value you wanted it to have . :up:

I can not express in words the anger I feel right now.

The Specialist 11-09-2006 08:41

Re: Floats and Decimal Rounding
 
is there a good way to fix this problem ?:|

Zenith77 11-09-2006 08:50

Re: Floats and Decimal Rounding
 
No, pawn uses the IEEE double floating point percision method for using floats. It basically creates a sliding window for binary to change float values, however you loose percision with this as shown here (but this is really the only method pawn can use, since the only data type it really has is a cell).

edit
Look at that link a couple of posts above.

The Specialist 11-09-2006 08:55

Re: Floats and Decimal Rounding
 
hmmm , that seems like a horable flaw on the points of compuphase to make a reliable flaoting point system with any accuracy. so the only way to deal with this is to over compinsate huh? thats interesting though :wink:

Zenith77 11-09-2006 09:00

Re: Floats and Decimal Rounding
 
They really didn't have a choice, everything revovles around the cell, unless you want to take a year of your life to redesign everything to implement real data types :p.


All times are GMT -4. The time now is 07:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.