初始化
commit
8eeeb6728a
|
@ -0,0 +1,35 @@
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>rikao18</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.example;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public class BigDecimalApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// 设置编码(仅在需要时启用)
|
||||||
|
try {
|
||||||
|
System.setOut(new java.io.PrintStream(System.out,true,"UTF-8"));
|
||||||
|
} catch (java.io.UnsupportedEncodingException e) {
|
||||||
|
System.err.println("无法设置UTF-8编码:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建两个BigDecimal对象
|
||||||
|
BigDecimal num1 = new BigDecimal("99.52");
|
||||||
|
BigDecimal num2 = new BigDecimal("77.52");
|
||||||
|
|
||||||
|
//加法计算
|
||||||
|
BigDecimal result = num1.add(num2);
|
||||||
|
System.out.println("加法计算结果:" + result);
|
||||||
|
|
||||||
|
//减法计算
|
||||||
|
result = num1.subtract(num2);
|
||||||
|
System.out.println("减法计算结果:" + result);
|
||||||
|
|
||||||
|
//乘法计算
|
||||||
|
result = num1.multiply(num2);
|
||||||
|
System.out.println("乘法计算结果:" + result);
|
||||||
|
|
||||||
|
//除法计算
|
||||||
|
//默认保留小数点后两位
|
||||||
|
result = num1.divide(num2, 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
System.out.println("除法计算结果:" + result);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue