DEV Community

leo
leo

Posted on • Updated on

openGauss type conversion function to_char(numeric/smallint/integer/bigint/double precision/real[, fmt])

to_char(numeric/smallint/integer/bigint/double precision/real[, fmt])

Description: Convert an integer or floating point value to a string in the specified format.

The optional parameter fmt can be of the following categories: decimal characters, "grouping" characters, plus and minus signs and currency symbols. Each category can have different templates, and templates can be reasonably combined. Common templates are: 9, 0, , (thousand separator), . (decimal point).
Templates can have modifiers like FM, but FM does not suppress 0s specified by template 0 and output.
To convert a value of type integer to a string corresponding to the hexadecimal value, use the template X or x.
Return value type: varchar

Example:
openGauss=# SELECT to_char(1485,'9,999');

to_char

1,485
(1 row)

openGauss=# SELECT to_char( 1148.5,'9,999.999');

to_char

1,148.500
(1 row)

openGauss=# SELECT to_char(148.5,'990999.909');

to_char

0148.500
Enter fullscreen mode Exit fullscreen mode

(1 row)
Copy after login

openGauss=# SELECT to_char(123,'XXX');

to_char

7B
(1 row)

Top comments (0)