extract digits from a number ?

Discussion in 'C++' started by mark, Jun 14, 2004.

  1. mark

    mark Guest

    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.
     
    mark, Jun 14, 2004
    #1
    1. Advertising

  2. "mark" <> wrote...
    > 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;
     
    Victor Bazarov, Jun 14, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loris_p
    Replies:
    3
    Views:
    375
    Roedy Green
    Jun 15, 2007
  2. bejiz
    Replies:
    12
    Views:
    634
  3. Chris Rebert
    Replies:
    1
    Views:
    418
    Grant Edwards
    Nov 5, 2010
  4. Tim Chase
    Replies:
    2
    Views:
    600
    Tim Chase
    Nov 6, 2010
  5. lolveley
    Replies:
    2
    Views:
    112
    7stud --
    Apr 30, 2009
Loading...

Share This Page