Math - Rounding - Challenge

FLOOR: 6
CEIL: 7
ROUNDED BY ONE DECIMAL: 6.3
ROUNDED BY TWO DECIMALS: 6.28

1 Like

Floor: 7.0
Ceil: 6.0
Dp 1: 2
Dp 2: 8

Great work in giving this challenge a go @Aletzr.
Unfortunately it looks like you’ve made a few mistakes.

You can think of rounding as “shortening” the original number by following specific rules.

For example, if the number was 6.284 we’d have:
Floor: 6
Ceiling: 7
1 dp: 6.3
2 dp: 6.28

Try giving it another go and if you’d like some extra help, just let me know.

Floor: 6
Ceiling: 7
First decimal: 6.3
Second decimal: 6.28

1 Like

6.283
Floor = 6
Ceiling = 7
1 Decimal = 6.3
2 Decimal = 6.28

1 Like

Your challenge is to take the number 6.283 and:

  1. Find the Floor of the number - 6
  2. Find the Ceiling of the number - 7
  3. Round the number to both 1 & 2 decimal places.

6.3 & 6.28

1 Like

Challenge Rounding numers:
6.283
Floor: 6
Ceiling: 7
1 Decimal : 6.3
2 Decimals: 6.28

Hope I got th e spoiler tag correct :slight_smile:

1 Like

6.283
floor => 6
ceil => 7
1 dec => 6.3
2 dec => 6.28

Floor of 6.283: 6
Ceiling of 6.283: 7
6.283 to 1 decimal: 6.3
6.283 to 2 decimals: 6.28

math

  1. Floor: 6
  2. Ceiling: 7
  3. Round to decimal places 1 & 2: 6.3 & 6.28

6.283
Floor - 6
Ceil - 7
1 Decimal - 6.3
2 Decimal - 6.28

round Challenge

I found this function

//Float as String With Precision!
FString GetFloatAsStringWithPrecision(float TheFloat, int32 Precision, bool IncludeLeadingZero=true)
{
        //Round to integral if have something like 1.9999 within precision
	float Rounded = roundf(TheFloat);
	if(FMath::Abs(TheFloat - Rounded) < FMath::Pow(10,-1 * Precision))
	{       
		TheFloat = Rounded;
	}
	FNumberFormattingOptions NumberFormat;					//Text.h
	NumberFormat.MinimumIntegralDigits = (IncludeLeadingZero) ? 1 : 0;
	NumberFormat.MaximumIntegralDigits = 10000;
	NumberFormat.MinimumFractionalDigits = Precision;
	NumberFormat.MaximumFractionalDigits = Precision;
	return FText::AsNumber(TheFloat, &NumberFormat).ToString(); 
}

If you need to print it, so it can be represented as a string. If it is for calculations, so it is just a float as it is and there is no need to set precision. As I understand this.

Floor: 6
Ceiling: 7
1 Decimals: 6.3
2 Decimals: 6.28

floor: 6
ceiling: 7
round 2: 6.28
round 1: 6.3

My answer
6.283 floor = 6

6.283 ceiling = 7

6.283 1dp = 6.3

6.283 2dp =6.27

6.283
Floor: 6.0
Ceiling: 7.0
1st decimal: 6.3
2nd decimal: 6.28

  1. Floor = 6
  2. Ceiling = 7
  3. Round: One decimal = 6.3, Two decimals = 6.28

6
7
6.28
6.3

Privacy & Terms