aspose file tools*
The moose likes Java in General and the fly likes Changing number format to NOT do Scientific Notation....ever... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Changing number format to NOT do Scientific Notation....ever..." Watch "Changing number format to NOT do Scientific Notation....ever..." New topic
Author

Changing number format to NOT do Scientific Notation....ever...

Erik Lanham
Greenhorn

Joined: Feb 21, 2009
Posts: 3
ok, so ive been working on a calculator program, and if i dare exceed 1 million it puts it into scientific notation. from looking around i tried the

import java.math.*; import java.text.*; thing with NumberFormat blah = new DecimalFormat(); and setting it to ("############");

and adding the blah.formatter(whatever output is here); that seems to appear everywhere i look. but after compiling then running the program. and inputing the values i need. i get this upon it trying to calculate it.

Exception in thread "main" java.lang.IllegalArgumentException: Cannot format giv
en Object as a Number
at java.text.DecimalFormat.format(DecimalFormat.java:480)
at java.text.Format.format(Format.java:133)
at BlueprintCalculatorTEST.run(BlueprintCalculatorTEST.java:102)
at acm.program.Program.runHook(Program.java)
at acm.program.Program.startRun(Program.java)
at acm.program.Program.start(Program.java)
at acm.program.Program.start(Program.java)
at acm.program.Program.main(Program.java)


any suggestions would be grand and much appreciated. (and theres no Doubles or anything. its JUST int's considering that the calculator is used for things that never have a decimal.)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10905
    
  12

What are you passing to the method - what kind of object? or are you passing a primitive?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Erik Lanham
Greenhorn

Joined: Feb 21, 2009
Posts: 3
well thats the thing.. theres not an object. like... heres a little example of this

int x = readInt("Number of Blueprints reuested (1-10): ");

if (x==1)//ONE BLUEPRINT
{
println("First Blueprint");

isogen = readInt("Amount of Isogen: ");
totaliso0 = isogen * runs;


theres a ton more to it, the thats basically what im doing. and wen i get my final output it always puts it to scientific notation, which i dont want.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

theres a ton more to it, the thats basically what im doing. and wen i get my final output it always puts it to scientific notation, which i dont want.


"ton more" of what? I don't even see a call to the format() method in the code that you did provide.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Erik Lanham
Greenhorn

Joined: Feb 21, 2009
Posts: 3
as i said. its a large base calculator program, but if i go past 1million it kicks it into scientific notation, from everything ive read it requires formatting for the number to not do that. i need it to give exact numbers, not scientific notation. if needed i can give you the program i got, this is all thats left to finish it. majority of the numbers will be in the hundred millions and the billions so i need it to not display scientific notation.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
Without seeing the actual code that uses the applyPattern and format methods it's hard to say what might be going on. Something like this works fine for me:


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing number format to NOT do Scientific Notation....ever...
 
Similar Threads
format a scientific notation double to a non scientific notation double
Urgent A method in Java which rounds 18 places to 8 places after decimal
Help Regarding Decimal Format Class
Scientific notation
Rounding problem