I have an issue only when the value is less than 1. Table decimal column value = 0.5, Required output format = '0.5' I am getting it as '.5' , i need it as '0.5'
The "stringf" function used above is downloaded from http://www.universalthread.com ASA Version 9.0.2.3702 asked 04 Feb '10, 11:03 Kumar |
Take a look at Breck's blog entry Readable, Correct, Concise Regards Thomas answered 04 Feb '10, 11:31 Thomas Dueme... @TDuemesnil, thank you. First thing i did is the omission of the $ symbol from the code, I am in middle east :-). And both working perfectly for 2 decimals, but there are some glitches when i increase it to 3. |
I copied code from Breck's blog, and did a small change to accept 3 decimals.
And here is the code to test both :-
Here is the output :- answered 04 Feb '10, 12:46 Kumar See the record 19 & 20, it is not prefixed with a 0 (zero). Increasing the decimals also have an effect on the thousand separator comma, on almost all the results. 2
You should adopt the following line
|
It will result in -0.990 but it will not have a thousand separator, but this might be unimportant? answered 05 Feb '10, 15:35 Martin STR() hs the side effect that is expects an approximate numeric value. As such with large numbers, rounding errors could result, cf. the question [http://sqlanywhere-forum.sap.com/questions/399/is-12345678901234566-00-the-correct-result-of-str-12345678901234567-0001-40-2]. This may or may not be important:) @Martin: Needless to say, I have just learned that from the other question:) @Volker: Thanks, I am aware that it's no perfect solution, but I had the feeling that maybe a suboptimal but simple solution might already help here. If Kumar really wants to work with the data, he will probably use a programmatic way to retrieve the data and then he has the power of the programming language to do any necessary formatting. |