Seperating Main And Fractional Numbers

This is a discussion on Seperating Main And Fractional Numbers within the C++ Programming forums, part of the General Programming Boards category; How do you get one FLOAT variable to seperate into a main number and fraction. i.e. If I had a ...

  1. #1
    Registered User Robert_Ingleby's Avatar
    Join Date
    Oct 2001
    Posts
    57

    Seperating Main And Fractional Numbers

    How do you get one FLOAT variable to seperate into a main number and fraction.

    i.e. If I had a FLOAT variable of 1.234, how do I get 1.234 into 2 new variables of 1.000 and 0.234.

    I hope you understand the question!.

    Rob.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    It's called modf(), and it's found in math.h

    Reading the manual page for it is up to you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    John
    Guest
    assign the float to an integer for the integer value.
    subtract that integer value from the original float to get the fractional part.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21