php 在php中将数字转换为十进制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3699509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:45:31  来源:igfitidea点击:

convert number to decimal in php

phpnumbersformat

提问by 109221793

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.

我有一个存储在变量中的数字。该数字从数据库中提取为 9900..我需要将此数字转换为 99.00,以便以 HTML 格式显示给客户。

I was wondering how can I achieve this in php.

我想知道如何在 php.ini 中实现这一点。

Thanks.

谢谢。

回答by jensgram

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

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

然后你可以随意使用round()number_format()

回答by Kristoffer Sall-Storgaard

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

您可以通过使用money_formatnumber_format来做到这一点,如果您要将其显示为价格,您应该查看money_format,否则, number_format是要走的路。

回答by 2ndkauboy

You can use the number_format()function for that:

您可以使用number_format()函数:

echo number_format(9900/100);