Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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.)
 
lowercase baba
Posts: 12893
63
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.
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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.
 
Rancher
Posts: 43016
76
  • 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:

 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic