Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Erik Lanham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you passing to the method - what kind of object? or are you passing a primitive?

 
Erik Lanham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Erik Lanham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic