简体   繁体   English

四舍五入从Teradata SQL助手提取的值时出现问题

[英]Issue in rounding off the values extracted from Teradata SQL assistant

I need to round off couple of fields that I extract from Teradata SQL assistant. 我需要四舍五入从Teradata SQL助手中提取的字段。 Currently I am using CAST(Field1 as numeric(20,2)) as Field1 18.529 is rounded to 18.53 but 36.425 is rounded to 36.42 instead I am expecting 36.43 How can this be achieved? 目前,我正在使用CAST(Field1作为numeric(20,2)),因为Field1将18.529舍入为18.53,但是将36.425舍入为36.42而不是期望36.43如何实现?

The rounding rules for CASTs depend on a global setting, RoundHalfwayMagUp in dbscontrol. CAST的舍入规则取决于全局设置dbscontrol中的RoundHalfwayMagUp。

You might try the ROUND function which defaults to the rounding rules you prefer: 您可以尝试使用ROUND函数,该函数默认为您喜欢的舍入规则:

ROUND(36.425,2)

I found an old post on a forum here which states that the RoundHalfwayMagUp controls whether .5 rounds up or down. 我发现了一个旧帖子在论坛上这里其中指出, RoundHalfwayMagUp控制0.5无论向上或向下取。 See the docs for more info 有关更多信息,请参阅文档

because in 36.425, 5 is near to 0 not to 10, if you put 36.426 it will round of to 36.43 因为在36.425中,5接近0而不是10,如果您输入36.426,它将四舍五入为36.43

Round : 回合:

It will work like below 它将像下面一样工作

between 0 and 5 > increment by 0( replaced ) 在0到5之间>以0递增(已替换)

between 5 to 10 > increment by 1 ( replaced) 在5到10之间>递增1(已替换)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM