cancel
Showing results for 
Search instead for 
Did you mean: 

Number to String Conversion Problem

Former Member
10,199

Hi There, I have an SQL problem I hope someone would be able to assist.

I need to covert a number to string with a specific format, i.e. not ending up the number with .0000 which doesn't make sense. Is there any function in SQL Anywhere that gets a number and a format mask and produces the required string?

Another one, regarding alternative to NVL function of Oracle. If I use the nullif in Strings, I still get the result as number which then get's converted. Any ideas how to prevent that?

Thanks, Dvir

Accepted Solutions (0)

Answers (2)

Answers (2)

VolkerBarth
Contributor

AFAIK, there's no such general "number-formatting function" (though it has been requested in the past...). However, there are some general data conversion functions like STR or CAST (or conversions to numerical data with fixed number of decimal places) that may be helpful in simple cases, such as

select str(6.1234), cast(6.1234567890 as varchar),
   cast(cast(6.1234567890 as numeric(10,2)) as varchar)

returns

6, 6.123456789, 6.12

The following FAQ may help further:

t1950
Participant
0 Kudos

the convert function will take a number and convert it to text. select convert( char( 20 ), 12345.6789 ) from table will convert the number to text but will not format it to 12,345.6789

VolkerBarth
Contributor
0 Kudos

AFAIK, "convert(char, myNumber)" is semantically identical to "cast(myNumber as char)" - i.e. as long as you don't use convert() with the optional "format-style" parameter, both work similar...