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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With