Home  >  Article  >  Database  >  mysql格式化小数

mysql格式化小数

WBOY
WBOYOriginal
2016-06-07 15:10:081107browse

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 今天遇到一个问题,格式化浮点数的问题,用format(col,2)保留两位小数点,出现一个问题,例如 SELECT FORMAT(12562.6655,2); 结果:12,562.67 查看文档:Formats the number X to a format like

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  今天遇到一个问题,格式化浮点数的问题,用format(col,2)保留两位小数点,出现一个问题,例如

  SELECT FORMAT(12562.6655,2);

  结果:12,562.67

  查看文档:Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part.整数部分超过三位的时候以逗号分割,并且返回的结果是string类型的。

  mysql> SELECT FORMAT(12332.123456, 4);

  -> '12,332.1235'

  mysql> SELECT FORMAT(12332.1,4);

  -> '12,332.1000'

  mysql> SELECT FORMAT(12332.2,0);

  -> '12,332'

  没有达到预期结果,想要的结果不要以逗号分隔,

  select truncate(4545.1366,2);

  结果:4545.13,直接截取不四舍五入,还是有问题。

  select convert(4545.1366,decimal);

  结果:4545.14,达到预期。

mysql格式化小数

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