Oracle number to char 研究

解决 number to char 补零问题

由于字段在DB中number类型 可以保存 int ,float ,double 数据.

当int 类型 时 直接转换 to_char 或者 || 不会出问题.但是当为float 或者 double 时 会出转换问题(0.25 --> .25 类似问题).

此Sql语句

decode(length(REPLACE(to_char(ACTUAL_VALUE),'.','') ),length(ACTUAL_VALUE),to_char(ACTUAL_VALUE),to_char(ACTUAL_VALUE,'FM99999990.9999'))

(即当int to_char,float doubleto_char(ACTUAL_VALUE,'FM99999990.9999'))可以解决此问题.

int 时 不变 , double ,float 时 0.25 -->0.25 非.25

此种'FM99999990.9999'规则为:小数点前 10位,小数点后最多4位,多于4位取舍.FM舍去空格.

猜你喜欢

转载自xue88ming.iteye.com/blog/2355071