Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting values from a double

 
Sri Ram
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a double number d = 15.33 .I want to do the below calculation.(ie) i want to seperate the whole number and the decimal part without using a splitter based on (.) to get the values.How can I do that??

e.g. 15.33 convert to 1520

Take decimal portion * 60 rounded. (0.33*60=20)

is what i want to perform? Please help.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do not you want a splitter based on (.) ?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Converting to text and splitting on the decimal point is both inefficient and subject to localisation issues (e.g. '.' versus ','). Using the Math library is the way to go, I think.

Look at Math.floor().

Compare and contrast to Math.ceil() and Math.round(), which have similar functionality, but subtle important differences.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic