• Post Reply Bookmark Topic Watch Topic
  • New Topic

Math.round  RSS feed

 
Lari Hopkins
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble getting currency to be displayed in pence as well as pounds, I added math.round in order to shorten the decimal number to 00.00 but now I have no decimal place displyed it seems. Any help gratefully received!
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
take a look at NumberFormat class and its Subclass DecimalFormat http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html


You can specify a pattern on how to Format numbers. Also check out the getCurrencyInstance() method.

Pascal
 
Lari Hopkins
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my currency converter program I have changed from math.round to decimal format so as to view pence as well as pounds in the readout. I have added

import java.text.*;

to te beginning and have added

df.format

into my setdisplay but now as soon as I press a button on the readout which uses df.format a list of exceptions appears...

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at DollarManager.entered20Pound(DollarManager.java:171)
at DollarConverter.jBut20PoundActionPerformed(DollarConverter.java:430)
at DollarConverter.access$1200(DollarConverter.java:25)
at DollarConverter$14.actionPerformed(DollarConverter.java:273)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

ANy suggestions as to what I have done wrong?!
[ November 25, 2006: Message edited by: Lari Hopkins ]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit the DollarManager.java file. Go to line 171. you should be in or near the entered20Pound() method. Please provide this code, along with a pointer to the exact line for line 171.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!