Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

10 Digit Precision

807603Feb 19 2008 — edited Feb 24 2008
Greetings,

I'm a high school math teacher implementing a "virtual" version of my state's testing calculator for use in class.

I've gotten fairly far, but I'm now to the point where I have to duplicate the calculator's precision. The calculator can display a maximum of 10 digits, so I need to round everything to 10 digits. I also need something flexible enough that numbers whose integer portion is greater than 10 digits are expressed in scientific notation.

I've made some progress using math context and BigDecimal. Here is my current "display whatever is supposed to be on the calculator" function:
	//Utility function for updating the display
	public void refresh()
	{
		MathContext rounder = new MathContext(10);
		BigDecimal convertedNumber= new BigDecimal(numberOnDisplay,rounder);
		
		theDisplay.updateNumber(convertedNumber.toString());
	}
But I have some problems:

1) Is there some way I can get these to automatically convert to scientific notation, as described above? Right now, I'm planning a soul-crushing amount of string voodoo.
2) Trailing zeros, when they are entered, should be displayed, but not when they are calculated. I figure I'll have to do this manually, but it's worth a hail-mary that some obscure format setting is out there.

That's all I can think of right now. Any help would be appreciated.
-Troy K
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 23 2008
Added on Feb 19 2008
8 comments
167 views