Page 1 of 1
Trim decimal places
Posted: Tue Jul 12, 2005 3:46 pm
by ddragas
I've got number in format 35603.822252
How to leave only two numbers after decimal decimal '.'? (trim or something)
I know that exist 'number_format($number, 2, ’.’, ’.’)' command, but I do not want to use this.
One more thing how to get formating number 35,603.82 to 35.603,82
Re: Trim decimal places
Posted: Tue Jul 12, 2005 3:47 pm
by hawleyjr
ddragas wrote:
I know that exist 'number_format($number, 2, ’.’, ’.’)' command, but I do not want to use this.
Why Not?
Posted: Tue Jul 12, 2005 3:57 pm
by ddragas
Becouse Im using function
viewtopic.php?t=33582 (author Burrito) and it is returning text 'Thirty Five Thousand Six Hundred and Three Point Eight Hundred and Twenty Two Thousand Two Hundred and Fifty Two'
So I need to trim all but two decimals
Posted: Tue Jul 12, 2005 4:28 pm
by pickle
So why don't you call number_format() before running ~Burrito's script?
Posted: Tue Jul 12, 2005 4:38 pm
by ddragas
If I do it before I get 'Thirty Five Point Eighty Two' (without Hundreds)
Posted: Tue Jul 12, 2005 4:51 pm
by pickle
Isn't that what you want? Do you want the string representation or do you want the digits themselves?
As for you second question:
PHP Manual wrote:string number_format ( float number [, int decimals [, string dec_point, string thousands_sep]] )
http://www.php.net/number_format
Posted: Tue Jul 12, 2005 4:53 pm
by ddragas
No it is not
Number is 35603.822252 and result in text is 'Thirty Five Point Eighty Two' (without Hundreds)
Posted: Tue Jul 12, 2005 5:07 pm
by pickle
The problem is the thousands separater. Call number format like this:
Code: Select all
number_format(35603.822252,2,'.','');
That will remove the thousands separator, and allow ~Burrito's code to work properly.
Posted: Tue Jul 12, 2005 5:09 pm
by ddragas
Shell I ask him to help me repair it? or will you try to help me?
Posted: Tue Jul 12, 2005 5:11 pm
by pickle
I was wrong (sort of) - read my previous post that has now been edited to eliminate all evidence of me being wrong

.
Posted: Tue Jul 12, 2005 5:14 pm
by ddragas
Thank you
Works great
Posted: Wed Jul 13, 2005 12:05 am
by theda
Oh, and by the way... Using European monetary format is slightly goofy in American programming languages isn't it?
Posted: Wed Jul 13, 2005 3:22 am
by onion2k
theda wrote:Oh, and by the way... Using European monetary format is slightly goofy in American programming languages isn't it?
Money was around before programming. It's the programming language that's goofy, not the other way round.