MySQL正在以小数形式切割'00' [英] MySQL is cutting '00' in decimals

查看:42
本文介绍了MySQL正在以小数形式切割'00'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小数列的表格,长度为 9,小数为 2.

I have a table with a decimal column with a lenght = 9 and decimals = 2.

如果我输入 21.59 的值(例如),它可以确定.

If I put a value of 21.59 (for example) it works ok.

如果我输入 52.00 它只写 52.我需要保留 52.00 代替.

If I put 52.00 it writes only 52. I need to keep 52.00 instead.

大师提问:数据库可以这样存储值吗?代替在选择中使用格式/转换来检索值...

Master question: Can the database store the value this way? Instead of using format/cast in select to retrieve the value...

如下所述,这是有道理的:

As noted bellow, this make sense:

您不必担心数据库中的显示格式问题级别,但在...显示级别"

"You shouldn't worry about display formatting issues at the database level but at the ... display level"

推荐答案

使用 FORMAT 函数:

Use the FORMAT function:

select format(mycolumn, 2) from mytable;

这也具有在数字中添加千位分隔符的效果,因此您会得到类似 123,456.70 的输出.如果这对您不起作用,有一些解决方法.

This also has the effect of adding thousand's separator into the number, so you would get output like 123,456.70. There are workarounds if this doesn't work for you.

鉴于 MySQL 没有世界上最好的数字格式化工具,像这样的显示问题通常在客户端代码中处理.

Given that MySQL doesn't have the world's best facilities for formatting numbers, display issues like this are usually handled in client code.

这篇关于MySQL正在以小数形式切割'00'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆