使用coma投射字符串以点浮动 [英] Cast string with coma to float with dot
本文介绍了使用coma投射字符串以点浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试投放
$value = floatval('14,5833');
到 float
有点像 14.5833
,但它返回我 14,5833
。
to a float
type I expect a value with dot like 14.5833
but it returns me 14,5833
.
我应该怎么做?
我不想使用任何字符串替换函数。
I wouldn't like to use any string replace functions.
推荐答案
您有两个选项:
- 将locale设置为使用点而不是coma 。例如。 setLocale(LC_ALL,'fr_BE.UTF-8');
- 在内部使用逗号,当要输出该数字时,使用 number_format
- Set locale to something that uses a dot instead of a coma. E.g. setLocale(LC_ALL, 'fr_BE.UTF-8');
- Keep using comma internally, and when you want to output that number, use number_format
这篇关于使用coma投射字符串以点浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文