extract digits from a number ?

M

mark

How to extract digits from a given number
say double number is 10.9876
extract two digits after decimal - 98
extract three digits after decimal - 987

and represent the extracted number as an integer.
 
V

Victor Bazarov

mark said:
How to extract digits from a given number
say double number is 10.9876
extract two digits after decimal - 98
extract three digits after decimal - 987

and represent the extracted number as an integer.

double number = 10.9876;
int twodigits = int(floor(number * 100)) % 100;
int threedigits = int(floor(number * 1000)) % 1000;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top