MSFN Forum: Urgent: Need help doing math in java - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Urgent: Need help doing math in java Rate Topic: -----

#1 User is offline   sevenalive 

  • Seven Update - Lead Developer
  • PipPip
  • Group: Members
  • Posts: 141
  • Joined: 23-July 05
  • OS:Windows 7 x64
  • Country: Country Flag

  Posted 20 September 2005 - 04:42 PM

how do i take a long number

ex. 40.344644

and make it to

40.3

basically round it.

any ideas

This post has been edited by Seven Alive: 20 September 2005 - 05:02 PM



#2 User is offline   aussiecanuck46 

  • Junior
  • Pip
  • Group: Members
  • Posts: 67
  • Joined: 14-May 04
  • OS:XP Pro x86
  • Country: Country Flag

Posted 20 September 2005 - 09:16 PM

I'd suggest using the round() method. It rounds a double value to an integer. But if you first multiply that double value by 10 and then round it you could then divide the rounded value by 10 into a double value.

#3 User is offline   matthewk 

  • Member
  • PipPip
  • Group: Members
  • Posts: 288
  • Joined: 07-June 05

Posted 30 September 2005 - 03:01 PM

You could take your value float/double num:
num = (int)num + (int)((num - (int)num)*10)

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy