Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Convert cents to dollars [closed]

Tags:

I'm using Stripe Payment. My prices are integers in cents:

050 1000 1250 2999 

I manipulate those numbers with my own class and no problem with that.

I'm looking the way to convert those numbers (cents) in dollars (always with decimals even if .00) like following:

0.50 10.00 12.50 29.99 

Any idea?

like image 919
Fredmat Avatar asked Jun 08 '15 15:06

Fredmat


People also ask

How do you convert cents to dollars and cents in Java?

Use division by 100 in combination with the 'int' primitive type to see how many dollars you have. For example, int dollars = cents/100; No matter what (int) value you have for cents, at the end of that operation, dollars will be an integer, so it will have the exact amount of dollars.


1 Answers

You can use number_format() in following way:

<?php  $value = 50;  echo number_format(($value /100), 2, '.', ' ');  ?> 

Output:- https://3v4l.org/tHigs

For more reference read the below link

number_format

like image 75
Anant Kumar Singh Avatar answered Sep 19 '22 01:09

Anant Kumar Singh