Raised This Month: $ Target: $400
 0% 

Floats and Decimal Rounding


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Politics
Junior Member
Join Date: Nov 2006
Old 11-09-2006 , 05:14   Floats and Decimal Rounding
Reply With Quote #1

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.
Politics is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 11-09-2006 , 05:15   Re: Floats and Decimal Rounding
Reply With Quote #2

http://forums.alliedmods.net/showthr...288#post401288
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
The Specialist
BANNED
Join Date: Nov 2006
Old 11-09-2006 , 05:22   Re: Floats and Decimal Rounding
Reply With Quote #3

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
The Specialist is offline
Send a message via AIM to The Specialist
Politics
Junior Member
Join Date: Nov 2006
Old 11-09-2006 , 05:25   Re: Floats and Decimal Rounding
Reply With Quote #4

Quote:
Originally Posted by Greenberet View Post
Still gives many trailing 0's or not the exact number

Quote:
Originally Posted by The Specialist View Post
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
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.
Politics is offline
The Specialist
BANNED
Join Date: Nov 2006
Old 11-09-2006 , 06:11   Re: Floats and Decimal Rounding
Reply With Quote #5

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 .
The Specialist is offline
Send a message via AIM to The Specialist
Zenith77
Veteran Member
Join Date: Aug 2005
Old 11-09-2006 , 08:24   Re: Floats and Decimal Rounding
Reply With Quote #6

Quote:
Originally Posted by The Specialist View Post
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 .
I can not express in words the anger I feel right now.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Old 11-09-2006, 08:32
The Specialist
This message has been deleted by The Specialist.
The Specialist
BANNED
Join Date: Nov 2006
Old 11-09-2006 , 08:41   Re: Floats and Decimal Rounding
Reply With Quote #7

is there a good way to fix this problem ?
The Specialist is offline
Send a message via AIM to The Specialist
Zenith77
Veteran Member
Join Date: Aug 2005
Old 11-09-2006 , 08:50   Re: Floats and Decimal Rounding
Reply With Quote #8

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.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
The Specialist
BANNED
Join Date: Nov 2006
Old 11-09-2006 , 08:55   Re: Floats and Decimal Rounding
Reply With Quote #9

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
The Specialist is offline
Send a message via AIM to The Specialist
Zenith77
Veteran Member
Join Date: Aug 2005
Old 11-09-2006 , 09:00   Re: Floats and Decimal Rounding
Reply With Quote #10

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.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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