简体   繁体   English

在SQL中将数字转换为两位十进制数字

[英]converting number into two decimal digits in sql

I am having this query which show the output as numer number 我有此查询,将输出显示为数字

SELECT  rlseamt  FROM ln01mast WHERE acno=214

I want to convert it to decimal amount for two digits ex:198.00 我想将其转换为两位数的十进制数,例如:198.00

You can use Number format models to have desired output. 您可以使用数字格式模型来获得所需的输出。

You can modify your query like this: 您可以像这样修改查询:

SELECT  TO_CHAR(rlseamt,'999D99')  FROM ln01mast WHERE acno=214

You should change the format model acrroding to the the length of NUMBER datatype, defined for rlseamt column. 您应该将格式模型更改为rlseamt​​列定义的NUMBER数据类型的长度。 Reason being, if you have values like 1234 in this column, then using the above format model, will not give you correct output, and the output will be replaced by something like #### . 原因是,如果此列中的值如1234,则使用上面的格式模型将不会为您提供正确的输出,并且输出将被####代替。 So, you would have to change the format model to 9999D99 因此,您必须将格式模型更改为9999D99

Use this document http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions181.htm 使用此文档http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions181.htm

You can either use 您可以使用

SELECT  TO_CHAR(rlseamt,'999D99')  FROM ln01mast WHERE acno=214

or 要么

SELECT  TO_CHAR(rlseamt,'000D00')  FROM ln01mast WHERE acno=214

second query will add a starting zero if the numbers before decimal is less than 3 characters..... 如果小数点前的数字少于3个字符,则第二个查询将添加一个起始零。

还有另一种方法,因为我无法使用此查询将零填充为零

SELECT  TO_CHAR(rlseamt,'9999999999999999999999D99')  FROM ln01mast WHERE acno=214

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

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