Home >Backend Development >PHP Tutorial >带千分位和小数位的数据写入数据库的问题

带千分位和小数位的数据写入数据库的问题

WBOY
WBOYOriginal
2016-06-23 13:26:191448browse

310
1,000.00
2,000


上面三个数据,写入数据库是310,1,2,有什么正确的方法写入数据库呢~


回复讨论(解决方案)

知道怎么做千分位的,没见过怎么取消千分位,number_format()

$num = 千分位的数字;$num .= ''; //转为字符串$newnum = str_replace(',', '', $num);$newnum += 0; //转为数字

这种业务逻辑一般都是从数据库读取出来之后再加上千分符

str_replace()替换就可

如果是要强制四位小数的话就字段定义decimal(M,N)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn