109221793
109221793

Reputation: 16867

convert number to decimal in php

I have a number stored in a variable. The number is pulled from the database as 9900..I need to convert this number to 99.00 in order to display to a customer in HTML.

I was wondering how can I achieve this in php.

Thanks.

Upvotes: 2

Views: 30159

Answers (3)

Kristoffer Sall-Storgaard
Kristoffer Sall-Storgaard

Reputation: 10636

You can do this by either using money_format or number_format, if you are going to display it as a price you should look at money_format, otherwise, number_format is the way to go.

Upvotes: 2

jensgram
jensgram

Reputation: 31508

$priceInCents = 9900;
$priceInDollars = $priceInCents / 100;

And then you can use round() or number_format() as you please.

Upvotes: 8

2ndkauboy
2ndkauboy

Reputation: 9377

You can use the number_format() function for that:

echo number_format(9900/100);

Upvotes: 3

Related Questions