Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
49 lines (38 loc) · 1.41 KB

File metadata and controls

executable file
·
49 lines (38 loc) · 1.41 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package string;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
public class Format {
static int a = 2;
public static void main(String[] args) {
//System.out.println(changeFormat(a));
format();
computeDoubleValue();
}
static int changeFormat(int a) {
if (a < 10) {
a = Integer.parseInt("0" + a);
}
return a;
}
static void format() {
String basic = "姓名:%2$s; 性别:%1$s; 分数:%3$d;";
SimpleDateFormat sdf = new SimpleDateFormat(basic);
String value = String.format(basic, "bingo", "男", 12);
System.out.println("value is " + value);//value is 姓名:男; 性别:bingo; 分数:12;
}
/**
* todo 注意 BigDecimal的参数需要为String,不能直接是double
*/
static void computeDoubleValue() {
double price = 1.52;
int count = 3;
/** 结果是 4.56**/
BigDecimal value1 = BigDecimal.valueOf(price);
double result = value1.multiply(BigDecimal.valueOf(count)).doubleValue();
System.out.println("11111 计算1值为result:"+result);
/** 结果为4.560000000000000053290705182007513940334320068359375**/
BigDecimal value2 = new BigDecimal(price);
String result2 = value2.multiply(new BigDecimal(count)).toString();
System.out.println("计算2值为result:"+result2);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.