Forum Moderators: coopster

Message Too Old, No Replies

Separate a non-integer into integer and fraction

         

maerk

6:28 pm on Apr 3, 2006 (gmt 0)

10+ Year Member



Is it possible to grab a non-integer number and separate it into an integer and numbers after the decimal place? (I'm not a maths expert, is there a name for the numbers after the decimal place?)

For example, I need to perform 15/12 = 1.25, then store 1 and 0.25 in separate variables.

barns101

7:16 pm on Apr 3, 2006 (gmt 0)

10+ Year Member



I would use the explode [uk.php.net] function.

maerk

12:56 pm on Apr 5, 2006 (gmt 0)

10+ Year Member



Actually I discovered the modulus operator: %

I wanted to convert a number of months into years and months, so 23 months = 1 year 11 months.

I was using 23/12 = 1.916666...

So: 1 year plus (0.916666... * 12) months

but 23 % 12 is 11 (the remainder) which is a lot better.

I knew there'd be a really basic thing -- probably why I couldn't find it easily.