How to make a number print out up to N decimal numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make a number print out up to N decimal numbers

Im trying to make a program to print out a number up to the amount of decimal points the user inputs. I only know the format method which uses % , but how can I use the number its inputted to make the print out ?

25th Jan 2017, 5:27 PM
Carlos Cintron
Carlos Cintron - avatar
2 Answers
0
123.45678 -> %.2f // output: 123.45
2nd Feb 2017, 6:02 AM
Иван Иванов
Иван Иванов - avatar
0
yes but what about using a value stored in a variable to know how many spaces it will choose a a decimal. for example the user chose to have 3 decimals and its stored in a variable called decimal how do I write it with that code.
2nd Feb 2017, 1:29 PM
Carlos Cintron
Carlos Cintron - avatar