Public Group

# How to get float value that is less then 1 without the higher part

This topic is 1990 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello.

I am kinda rusty in language so il just make example code;

I need this

float number = 1.332;
float newNumber = RemoveBigNumber(number);
//newNumber = 0.332;


what is the std function for such a method? i cant find it in

http://www.cplusplus.com/reference/cmath/

Edited by BaneTrapper

##### Share on other sites

Just do something like this

float RemoveIntegerPart(float n)
{
return n - (int)n;
}


##### Share on other sites

Look at it from a different angle instead: how do you obtain the integer part so that you can subtract it from the original number? You can cast the float to an integer, or using the floor function, for example.

##### Share on other sites
float RemoveWholePart (float N) {
return N - (int)N;
}

can't delete it.

Edited by dejaime

##### Share on other sites

With c++11:

float number = 1.332;

float truncatedNumber = trunc(number);

float wantedNumber = number - truncatedNumber;

##### Share on other sites

I can't think of any circumstances where you want the answer to be outside of [0,1), so I wouldn't use truncation.

True -- if negative numbers don't matter, floor would be preferred instead of trunc.

##### Share on other sites

modf returns the fractional and integer part of a floating point number.

If you do it with subtraction then remember to check that it gives you the answer you want for negative numbers.

This is the solution i ended up using.

Thank you on help and i kinda forgot i made this topic .

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22