![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
-0.01 (1 row) |
#2
| |||
| |||
|
|
select to_number('1,000', '999,999') returns '100'. |
#3
| |||
| |||
|
|
I'm not entirely convinced this is a bug. I get the right answer from regression=# select to_number('001,000', '999,999') ; to_number ----------- 1000 (1 row) It's arguable that to_number() should throw an error when the input doesn't match the format, but right now it doesn't ... |
#4
| |||
| |||
|
|
On Sun, Nov 21, 2004 at 20:10:08 -0500, Tom Lane wrote: I'm not entirely convinced this is a bug. I get the right answer from regression=# select to_number('001,000', '999,999') ; to_number ----------- 1000 (1 row) It's arguable that to_number() should throw an error when the input doesn't match the format, but right now it doesn't ... It seems strange to me that to_char(1000,'999,999') works (it returns 1,000), but the reverse doesn't. I want to convert a formatted number with group separators, but I don't know how many digits it has: should I count the digits myself and adapt the mask (which is a customization and thus entered by the user)? |
#5
| |||
| |||
|
|
On Mon, 22 Nov 2004, David Schweikert wrote: On Sun, Nov 21, 2004 at 20:10:08 -0500, Tom Lane wrote: I'm not entirely convinced this is a bug. I get the right answer from regression=# select to_number('001,000', '999,999') ; to_number ----------- 1000 (1 row) It's arguable that to_number() should throw an error when the input doesn't match the format, but right now it doesn't ... It seems strange to me that to_char(1000,'999,999') works (it returns 1,000), but the reverse doesn't. I want to convert a formatted number with group separators, but I don't know how many digits it has: should I count the digits myself and adapt the mask (which is a customization and thus entered by the user)? No, but I think you're supposed to use FM in such cases. select to_number(1000, 'FM999,999'); |
#6
| |||
| |||
|
|
No, but I think you're supposed to use FM in such cases. select to_number(1000, 'FM999,999'); |
#7
| |||
| |||
|
|
No, but I think you're supposed to use FM in such cases. select to_number(1000, 'FM999,999'); |
#8
| |||
| |||
|
|
Stephan Szabo <sszabo (AT) megazone (DOT) bigpanda.com> writes: No, but I think you're supposed to use FM in such cases. select to_number(1000, 'FM999,999'); Good point --- I had forgot about FM. In that case there *is* a bug here, but I'm not sure if it's with to_char or to_number: regression=# select to_number(to_char(1000, 'FM999,999'),'FM999,999'); to_number ----------- 1000 (1 row) regression=# select to_number(to_char(1000, '999,999'),'999,999'); to_number ----------- 100 (1 row) |
|
Whatever your opinion is about the behavior of the non-FM format, surely to_char and to_number should be inverses. |
#9
| |||
| |||
|
|
It's to_number() bug. I'm not sure if now (before release) is good time to fix it. The code of to_number() is not stable for changes and maybe we can fix this bug add some other new... |
|
I already work on new version for next release. It will use unit-tests -- I hope it will prevent a lot of bugs like this. |
![]() |
| Thread Tools | |
| Display Modes | |
| |