Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to format a double output

$
0
0
Hey guys,

So I want to format a number 54.366586669985, but I want the users to decide how many places they want they want to go to. So I asked them how many places they want to go to in a variable
Scanner scan = new Scanner(System.in);
int placesnum;
double num;

System.out.print("Enter a double number: ")
num =  scan.nextDouble();

System.out.print("How many places you want the number print to? ")
placesnum = scan.nextInt();


so for example they input 45.6666666666, but they only want it to print to the second decimal 45.66 so they would input in the second option 2

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>