1. I created a table in my Informix database: CREATE TABLE scentific_notation(floatvalues float)
2. I inserted these values: insert into scentific_notation values(2835121.634679258) insert into scentific_notation values(978696.1697495114) insert into scentific_notation values(2307377.07214382) insert into scentific_notation values(2336955.5022556856) insert into scentific_notation values(1888293.6396578003) insert into scentific_notation values(2304406.572121913)
3. I do a sum of the values SELECT sum(floatvalues)FROM scentific_notation
JDBC just returns a number. And numbers don't have any inherent format in Java. If you want to display it in some particular format (scientific or otherwise) then use a NumberFormat object to do that.
Also, if you don't like the way that this DbVisualizer thing is formatting your numbers, then your complaint is about DbVisualizer and not about JDBC. JDBC just returns a number, it doesn't format the number.
So the getObject() method of ResultSet is probably returning a Float or a Double (you could easily test this in you code if you want to find out). And you are adding this value to a StringBuffer which you then output to the console, without imposing any formatting (i.e. just using the default formatting provided by the JRE).
So, update my test class to do this:
And see what format the number takes. Then re-read Paul Clapham's post (paying particular attention to the line "...numbers don't have any inherent format in Java") and read the JavaDocs for the NumberFormat class.
Originally posted by Sivaraman Lakshmanan: Hi, Did you tried using java.math.BigDecimal class?
Changing the type is not addressing the underlying problem; that numbers in Java have no inherent format. If you want a number to be displayed in a particular format, you are going to have to define that format.
Pitty it doesn't keep the existing format in the db.
Databases, like Java don't hold any information about the format of a number. Why should they? In mathematics the format is irrelevant.
I hope formating a large number of values from the database is performant.
I would be amazed if this had any noticable effect on the performance of your application. But then you are in the position to see - test it and find out. [ September 20, 2006: Message edited by: Paul Sturrock ]