Re: Mapping Java BigDecimal
От | Kevin Grittner |
---|---|
Тема | Re: Mapping Java BigDecimal |
Дата | |
Msg-id | 4B5589EE020000250002E76C@gw.wicourts.gov обсуждение исходный текст |
Ответ на | Mapping Java BigDecimal (Jakub Bednář <jakub.bednar@b2bcentrum.cz>) |
Список | pgsql-jdbc |
Thomas Kellerer <spam_eater@gmx.net> wrote: > Craig Ringer, 19.01.2010 05:37: >> regress=> insert into test (x) values ('3'); >> INSERT 0 1 >> regress=> insert into test (x) values ('3.0'); >> INSERT 0 1 >> regress=> insert into test (x) values ('3.00'); >> INSERT 0 1 >> regress=> insert into test (x) values ('3.000'); >> INSERT 0 1 >> regress=> select * from test; >> x >> ------- >> 3 >> 3.0 >> 3.00 >> 3.000 >> (4 rows) > My first question: why does anyone pass a numeric value as a > string ;) Forget PostgreSQL for just a moment; try this in Java: import java.math.BigDecimal; class BigDecimalTests { public static void main(String[] args) { BigDecimal x; x = new BigDecimal(3.000); System.out.println(x.toPlainString()); x = new BigDecimal("3.000"); System.out.println(x.toPlainString()); x = new BigDecimal(1.01); System.out.println(x.toPlainString()); x = new BigDecimal("1.01"); System.out.println(x.toPlainString()); } } For those without Java to play along at home, the result of compiling and running this are: 3 3.000 1.0100000000000000088817841970012523233890533447265625 1.01 On top of that, in PostgreSQL '3.000' is *not* a character string, as you are probably assuming. It is treated as type UNKNOWN until it has to be resolved (similar to the treatment of a NULL literal), so it can be interpreted as a literal of some other type. -Kevin
В списке pgsql-jdbc по дате отправления: