In my program the user inputs the number of decimal places he requires in an output. I save this input as deci. How do I use this variable deci as a precision modifier?
Sample: Input a number: 23.6788766 Input number of decimals: 2 Output: 23.67
If it is C you can do:
float floatnumbervalue = 42.3456;
int numberofdecimals = 2;
printf("%.*f", numberofdecimals, floatnumbervalue);
In C, for example to change the default precision of 6 digits to 8:
int precision = 8;
printf("%.*f\n", precision, 1.23456789);
The precision argument has to be of type int
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With