Raised This Month: $ Target: $400
 0% 

truncating float to an int


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MALON
Member
Join Date: Jan 2008
Old 08-19-2008 , 09:26   truncating float to an int
Reply With Quote #1

How do I take a float, such as 125.9925 and make it 125 when the trailing decimal size will be unknown?

When I can't typecast from float to an int like in Java or C++, I normally take 125 - (125.9925%1) but I can't do that in pawn because I can't use the modulo operator on floats.

Thanks!
MALON is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 08-19-2008 , 09:31   Re: truncating float to an int
Reply With Quote #2

http://www.amxmodx.org/funcwiki.php?...loat&go=search

That gives you all the functions with "float" in their name.

The specific one you want is: http://www.amxmodx.org/funcwiki.php?go=func&id=73
__________________
Brad is offline
MALON
Member
Join Date: Jan 2008
Old 08-19-2008 , 09:53   Re: truncating float to an int
Reply With Quote #3

Thanks Brad, I looked there a thousand times, but it never occurred to me that floatround_down is the same as truncating.

Last Question:

How can I retrieve just the trailing digits? i.e. 125.9925 and get .9925 (or 9925 with no decimal) Sorry, I'm used to the modulo operator and I feel naked without it now.
MALON is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-19-2008 , 12:43   Re: truncating float to an int
Reply With Quote #4

Quote:
Originally Posted by MALON View Post
Thanks Brad, I looked there a thousand times, but it never occurred to me that floatround_down is the same as truncating.

Last Question:

How can I retrieve just the trailing digits? i.e. 125.9925 and get .9925 (or 9925 with no decimal) Sorry, I'm used to the modulo operator and I feel naked without it now.
floatfract()
danielkza is offline
Old 08-19-2008, 12:49
XxAvalanchexX
This message has been deleted by XxAvalanchexX. Reason: didn't read the entire post, sorry
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-19-2008 , 12:51   Re: truncating float to an int
Reply With Quote #5

Quote:
Originally Posted by XxAvalanchexX View Post
Pawn has the modulus operator: %
I don't think % works on floats. There's no rest if any of the operands is a float.
danielkza is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-19-2008 , 15:16   Re: truncating float to an int
Reply With Quote #6

This is a pretty dirty way to do it, but here is my idea:

Code:
new Float:rational; // set rational to your number new integer = floatround(rational, floatround_floor); new Float:decimal = rational - float(integer); /* Example: rational = 32.5 integer = floatround(32.5, floatround_floor) integer = 32 decimal = 32.5 - float(32) decimal = 32.5 - 32.0 decimal = 0.5 */
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-19-2008 , 15:22   Re: truncating float to an int
Reply With Quote #7

Like danielkza said, floatfract() exists for that.
__________________
Arkshine 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 03:13.


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