Reply
float digits
Old 04-29-2007, 01:45 AM float digits
NullPointer's Avatar
Will Code for Food

Posts: 482
Name: Matt
Location: Irvine, CA
I've been looking all through the docs and I can't figure out how to set the number of digits to be displayed when printing a float (ie 1.23423522 to 1.23). I'm trying to avoid removing the extra digits by manipulating the float as a string as that would just make things messy.
__________________
http://tinsology.com/ - Under construction
NullPointer is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-29-2007, 03:12 AM Re: float digits
Junior Talker

Posts: 4
Location: in your browser

number_format
($number, 2, '.', '');

where 2 is the number of decimal you want to appear
__________________
Submit URL
[Free Web Directory] - no reciprocal - no email needed for inclusion.
brealmz is offline
Reply With Quote
View Public Profile Visit brealmz's homepage!
 
Old 04-29-2007, 04:33 AM Re: float digits
NullPointer's Avatar
Will Code for Food

Posts: 482
Name: Matt
Location: Irvine, CA
Thanks a lot. I used to know that, completely forgot. Must be losing my mind. Or maybe I've been coding too long.
__________________
http://tinsology.com/ - Under construction
NullPointer is offline
Reply With Quote
View Public Profile
 
Old 04-29-2007, 06:58 AM Re: float digits
kaisellgren's Avatar
Extreme Talker

Posts: 214
Name: Kai Sellgren
Location: Finland
or by regexes:
PHP Code:
<?php

$value 
2.543543;

echo 
preg_replace('/^(\d+\\.\d{2}).*$/','$1',$value);

?>
__________________
Adept Web Community
kaisellgren is offline
Reply With Quote
View Public Profile Visit kaisellgren's homepage!
 
Old 04-29-2007, 09:48 AM Re: float digits
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
@kaisellgren
Why would you complicated you're self by using pregmatch when there is a perfect function number_format that does much more pregmatch
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-29-2007, 01:34 PM Re: float digits
kaisellgren's Avatar
Extreme Talker

Posts: 214
Name: Kai Sellgren
Location: Finland
Quote:
Originally Posted by solomongaby View Post
@kaisellgren
Why would you complicated you're self by using pregmatch when there is a perfect function number_format that does much more pregmatch
I never said I would do it that way. I just gave an alternative option.
__________________
Adept Web Community
kaisellgren is offline
Reply With Quote
View Public Profile Visit kaisellgren's homepage!
 
Reply     « Reply to float digits
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14415 seconds with 13 queries