playMaker

Author Topic: Round a float up to nearest integer, and separate the remainder as new float?  (Read 1307 times)

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
I need to round a float up to the nearest integer, and I also need to separately store the float's remainder to do operations on it. I'm not sure which actions are best for this kind of thing. "Float Round to Nearest" won't do it, as I need to say "is the float an integer? if not, round it up to the next integer." What's the best way to tackle this?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.

You could use Convert Float to int. but you would need to use it 2x if you want nearest.

1 use "Convert Float to int" and set rounding to 'Nearest' for the int value.

Then use "Convert Float to int" again (use a different int variable)
But set Rounding to 'Round Down'

Then use the result to deduct from the float to get the remaining.

ch1ky3n

  • Full Member
  • ***
  • Posts: 208
or you could multiply it by 1000
Example :

float_YourVariable = 6.25
float_YourVariableThousand = 6250

Convert it to int
int_YourVariable= 6*1000 = 6000
int_YourVariableThousand = 6250     

subtract 6250 - 6000
then convert it back to float and divide it by 1000 = 0.25