Format number to 2 decimal places(将数字格式化为 2 位小数)

本文介绍了将数字格式化为 2 位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何输出一个带有 2 个小数位的数字,而不对原始数字进行四舍五入.

I would like to know how can I output a number with 2 decimal places, without rounding the original number.

例如:

2229,999 -> 2229,99

我已经试过了:

FORMAT(2229.999, 2)
CONVERT(2229.999, DECIMAL(4,2))

推荐答案

您想使用 TRUNCATE 命令.

https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_truncate

这篇关于将数字格式化为 2 位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!