Wednesday, 15 February 2012

php - Padding zeroes to Price -



php - Padding zeroes to Price -

$price = 10.00; list($dollars, $cents) = explode('.', $price); echo $dollars . '.' . $cents;

... works except zeros omitted. 10.00 becomes 10 , 10.10 becomes 10.1

i see there's padding function strings, numbers or floats?

how prepare this?

use sprintf

$digit = sprintf("%02d", $digit);

for more information, refer documentation of sprintf.

php

No comments:

Post a Comment