char转换的数字不适用于领导0

发布于 2025-01-24 16:00:53 字数 278 浏览 4 评论 0原文

我有一个将数字转换为字符的情况。

但是,当我尝试将它们转换为char时,丢失了0。 因此,我尝试使用以下方法进行转换。

从dual中选择rtrim(to_char(0.5,'fm90.099'),'。');

但这与00.500不起作用。 00.500也为0.50 110.50作为#######。要使此情况工作,我需要将其更改为to_char(110.50,'fm990.099)。但是,如果有4位数字,它将再次起作用。 我也不确定生产系统可以拥有多少位数字。 是否还有其他可以将数字转换为0的字符。

I have a case to convert the numbers to character.

But the 0 are missing when i try to convert them to char.
So i tried to convert with the following method.

select rtrim(to_char(0.5, 'FM90.099'), '.') from dual;

But this doesnt work with 00.500. 00.500 also comes as 0.50
and 110.50 comes as #######. to make this case work i need to change this as to_char(110.50,'FM990.099). but again it wont work if there is a 4 digit number.
I am also not sure how many digits can the production system have.
is there any other to convert number to char with which the 0's doesnt miss.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不即不离 2025-01-31 16:00:53

放入足够的领先和尾随9 s,以说明您的最高精度和比例。如果格式掩码不够大,请增加9 s的数量,直到为止。

SELECT RTRIM(TO_CHAR(value, 'FM999999999999999999990.99999999'), '.') AS formatted_number
FROM   table_name;

对于示例数据:

CREATE TABLE table_name (value) AS
select 0.5     from dual UNION ALL
select 0.5000  from dual UNION ALL
select 0000.5  from dual UNION ALL
select 000.500 from dual UNION ALL
select 1e10    from dual UNION ALL
select 110.1234567 from dual;

输出:

formatted_number
0.5
0.5
0.5
0.5
10000000000
110.1234567

db&lt; Ferrer“>在这里 < /em>

Put in sufficient leading and trailing 9s to account for your maximum precision and scale. If the format mask is not big enough then increase the number of 9s until it is.

SELECT RTRIM(TO_CHAR(value, 'FM999999999999999999990.99999999'), '.') AS formatted_number
FROM   table_name;

Which, for the sample data:

CREATE TABLE table_name (value) AS
select 0.5     from dual UNION ALL
select 0.5000  from dual UNION ALL
select 0000.5  from dual UNION ALL
select 000.500 from dual UNION ALL
select 1e10    from dual UNION ALL
select 110.1234567 from dual;

Outputs:

FORMATTED_NUMBER
0.5
0.5
0.5
0.5
10000000000
110.1234567

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文