19-6 / 24 Job: a double fractional number, rounding to two decimal places according to

☞ requirements

The type of a double decimals, rounded to two decimal places in accordance with

 

☞ implementation

1. Obtain a fractional type double

2. BigDecimal package operates setScale

3. The output

 

☞ Code Content

 

Circulation Package; 



/ **
* @author 9527
* /

// import scanned packages
Import java.util.Scanner;
// Import fractional packet
Import java.math.BigDecimal;


public class a Decimal {
static Scanner Scanner new new SC = (the System. in);

public static void main (String [] args) {
// prompted to enter a decimal
System.out.println ( "Please enter a decimal number, at least three to one decimal place:");
// receiving a decimal
double decimal sc.nextDouble = ();
the BigDecimal the BigDecimal BD new new = (decimal);
BD = bd.setScale (2, BigDecimal.ROUND_HALF_UP);
System.out.println ( "outputting rounded to two decimal places:" + BD);
}

}

 

☞ operating results

 

 

 

☞ problems in the implementation process

 Groping for a long time or not using the API to solve the problem, you need to learn the skills API query

 

 

 

 

Guess you like

Origin www.cnblogs.com/twuxian/p/11079021.html