package com.njcn;

import com.njcn.csdevice.CsDeviceBootApplication;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import java.math.BigDecimal;
import java.math.RoundingMode;

@RunWith(SpringRunner.class)
@WebAppConfiguration
@SpringBootTest(classes = CsDeviceBootApplication.class)
public class BaseJunitTest {

    public static void main(String[] args) {
        double num1 = 123.456;
        double num2 = 123.4;
        double num3 = 123.0;

        System.out.println(roundToTwoDecimalPlaces(num1)); // 输出: 123.46
        System.out.println(roundToTwoDecimalPlaces(num2)); // 输出: 123.40
        System.out.println(roundToTwoDecimalPlaces(num3)); // 输出: 123.00
    }

    public static double roundToTwoDecimalPlaces(double num) {
        // 乘以100，然后四舍五入，再除以100
        return Math.round(num * 100.0) / 100.0;
    }
}
