Raised This Month: $51 Target: $400
 12% 

How do you


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bottiger
AlliedModders Donor
Join Date: Dec 2010
Old 10-06-2018 , 18:47   How do you
Reply With Quote #1

There seems to be no way to show floats below 6 decimal points. I tried using bit manipulation on the float and it doesn't seem to give accurate numbers at all.

Code:
float value = 0.0000001
PrintToServer("%e", value);  // prints e
__________________
bottiger is offline
cra88y
AlliedModders Donor
Join Date: Dec 2016
Old 10-06-2018 , 19:13   Re: How do you
Reply With Quote #2

I think you can use:
PHP Code:
float value 0.0000001
PrintToServer
("%.2f"value); 
(2 being the decimal places to display)

Last edited by cra88y; 10-06-2018 at 19:15.
cra88y is offline
bottiger
AlliedModders Donor
Join Date: Dec 2010
Old 10-06-2018 , 19:17   Re: How do you
Reply With Quote #3

Quote:
Originally Posted by cra88y View Post
I think you can use:
PHP Code:
float value 0.0000001
PrintToServer
("%.2f"value); 
(2 being the decimal places to display)
That shows 0.00
__________________
bottiger is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-06-2018 , 19:21   Re: How do you
Reply With Quote #4

Quote:
Originally Posted by bottiger View Post
That shows 0.00
...you were supposed to replace the 2 with the number of digits you wanted to display.

Although, since floating point numbers aren't particularly accurate, you may still run into issues.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
bottiger
AlliedModders Donor
Join Date: Dec 2010
Old 10-06-2018 , 19:22   Re: How do you
Reply With Quote #5

I don't know how low it will go so I don't want to do %.1000f
__________________
bottiger is offline
cra88y
AlliedModders Donor
Join Date: Dec 2016
Old 10-06-2018 , 19:23   Re: How do you
Reply With Quote #6

Floats are 32 bit in sourcemod so you can't have that much precision, I'd recommend just rounding it..

Last edited by cra88y; 10-06-2018 at 19:26.
cra88y is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 10-06-2018 , 20:46   Re: How do you
Reply With Quote #7

Quote:
Originally Posted by bottiger View Post
Code:
PrintToServer("%e", value);  // prints e
SM doesn't support %e (or %g).

Quote:
Originally Posted by bottiger View Post
I don't know how low it will go so I don't want to do %.1000f
It's pretty unclear what you mean by this. If you mean how many digits you can specify there, then as many as you want. If you mean you really want to remove trailing zeroes, then you should sprintf it and cut them off yourself. (If you want scientific notation like %e, you would also have to do it yourself.)

Quote:
Originally Posted by cra88y View Post
Floats are 32 bit in sourcemod so you can't have that much precision, I'd recommend just rounding it..
Floats have their problems, but a 32-bit float can exactly store 2^-126 (or 2^-139 for denormals).
Fyren 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 11:08.


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