从trunc()函数返回的数字中删除尾随零 [英] Remove trailing zeroes from number returned by trunc() function

查看:67
本文介绍了从trunc()函数返回的数字中删除尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下方式截断PostgreSQL中的数字:

I am trying to truncate numbers in PostgreSQL with:

SELECT trunc(31.71429,15); 

我有这个输出:

31.714290000000000

但是在Oracle中,我有这个:

But in Oracle I have this:

31.71429

如何获得与Oracle相同的输出?

How can have the same output as in Oracle?

推荐答案

是正确的,您的问题"在于 display -文本表示形式.因此,请根据您的喜好使用 to_char()格式化数字.您可以使用显示修饰符 FM 来取消微不足道的"0":

The value is correct, your "problem" is with the display - the text representation. So use to_char() to format numbers to your liking. You can use the display modifier FM to suppress insignificant '0':

SELECT to_char(trunc(31.71429,15), 'FM9999999999.999999999999999') 

产生所需的结果-以 text 显示(逗号前最多10位,逗号后最多15位-如果可以更多,请添加更多):

Produces the desired result - as text for display (up to 10 digits before and 15 after the comma - add more if there can be more):

'31.71429'

BTW,手册对此有点误导.它说:

BTW, the manual is a bit misleading about that. It says:

前缀填充模式(禁止前导零和填充空格)

prefix fill mode (suppress leading zeroes and padding blanks)

但是'FM'也抑制了不重要的 trailing 零.我提交了文档错误报告.

But 'FM' also suppresses insignificant trailing zeroes. I filed a documentation bug report.

这篇关于从trunc()函数返回的数字中删除尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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