 How can I make the output be 14.45 when the input is 3 because the output right now is 14.445? | Sololearn: Learn to code for FREE!

0

# How can I make the output be 14.45 when the input is 3 because the output right now is 14.445?

Here is the code: https://code.sololearn.com/chSr4MpAZc07/?ref=app

+2

From the c++ compiler VS2019 I'm using, you can use std::setprecision(n) where n is an integer denoting the length after decimal but then this function does not exist on sololearn Also c++ unlike most other languages does not provide a direct method that let you round up a number to a specific decimal place. However, a quick mathematical approach is to use res = std::round(n * 100) / 100; n = priceT (in your code) You must include the <cmath> header file, that's where the std::round function is from

+1

You could round the result

+1

***round the number*** or format the output string

0

Lisa Ooh, I understand! The only problem is that i only know the function 'ceil(varr)' but this one rounds up the number. I only want to round up the second positions after the coma. How?

0

Have you tried to solve this by Googling for approaches? I found this for instance: https://www.geeksforgeeks.org/rounding-floating-point-number-two-decimal-places-c-c/

0

0

change the second factor 7/100 for 29/270