Hi,
I have a price file in the following format:
320 = £3.20
2500 = £25.00
27380 = £273.80
Is there a php function that will automatically place the decimal correctly or should I just write a function to place the decimal 2 digits from the right?
Automatic Decimal Placement
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Automatic Decimal Placement
The key is dividing by 100 and then telling it to add 2 decimal places:
Code: Select all
$pence = '320';
$pounds = sprintf("%01.2f", $pence / 100);
//or
$pounds = number_format($pence / 100, 2);mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Automatic Decimal Placement
Thanks bud! 
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Automatic Decimal Placement
Two in a row? How is this possible?
Re: Automatic Decimal Placement
Lol a little different to my question but same principal. Gotta admit the odds on that are pretty low. 