I'm trying to convert a number to a string and apply a format using to_Char
in an Oracle database.
This is what I'm after (example of the value on the left and what I after on the left):
0 --> 0
0.29 --> 0.29
25319,76 --> 25,319.76
12252,136456 --> 12,252.13
Best format I can come up with is this in SQL:
to_char(var, 'B99,999,999,999.09')
This is the result:
0 --> nothing
0.29 --> .29
25319,76 --> 25,319.76
12252,136456 --> 12,252.13
So my issue is the 0.29 and 0. How can I get that part to work?
BR Kresten
The
B
format model:And since you don't want a blank integer part then you probably don't want to use the
B
format model; instead, you want theFM
format model that:You can use
RTRIM( TO_CHAR(var, 'FM99,999,999,990.99' ), '.' )
.For example:
Which, for the sample data:
Outputs:
db<>fiddle here