类 CalculationUtil

java.lang.Object
cn.vorbote.core.utils.CalculationUtil

public class CalculationUtil extends Object

Calculation Util can help you with high precision math calculation.

This util is made by Github User @sunzsh, and the source code location is Github Gist

Note: Some changes was made by Github user @vorbote because of the deprecation of method BigDecimal.setScale(int, int), all call to this method was moved to BigDecimal.setScale(int, RoundingMode).

Created at 5/26/2022 11:31 PM
作者:
sunzsh, vorbote
  • 方法详细资料

    • startOf

      public static CalculationUtil startOf(Number value)
      The initial value of start.
      参数:
      value - The initial value.
      返回:
      The CalculationUtil instance.
    • add

      public CalculationUtil add(Number other)
      Add a number to the original figure.
      参数:
      other - The other number.
      返回:
      The calculated instance.
    • add

      public CalculationUtil add(Number other, Integer beforeOperateScale)
      Calc: the original value add the other number.
      参数:
      other - The other number to be added.
      beforeOperateScale - Round other to beforeOperateScale decimal places before doing adding.
      返回:
      The calculated instance.
    • subtract

      public CalculationUtil subtract(Number other)
      Calc: the original value subtract the other number.
      参数:
      other - The value to be subtracted.
      返回:
      The calculated instance.
    • subtract

      public CalculationUtil subtract(Number other, Integer beforeOperateScale)
      Calc: the original value subtract the other number.
      参数:
      other - The value to be subtracted.
      beforeOperateScale - Round other to beforeOperateScale decimal places before doing subtracting.
      返回:
      The calculated instance.
    • multiply

      public CalculationUtil multiply(Number other)
      Calc: the original value multiply the other number.
      参数:
      other - The value to be multiplied.
      返回:
      The calculated instance.
    • multiply

      public CalculationUtil multiply(Number other, Integer beforeOperateScale)
      Calc: the original value multiply the other number.
      参数:
      other - The value to be multiplied.
      beforeOperateScale - Round other to beforeOperateScale decimal places before doing multiplication.
      返回:
      The calculated instance.
    • divide

      public CalculationUtil divide(Number other)
      Calc: the original value divide the other number.
      参数:
      other - The value to be divided.
      返回:
      The calculated instance.
    • divide

      public CalculationUtil divide(Number other, Integer beforeOperateScale)
      Calc: the original value divide the other number.
      参数:
      other - The value to be multiplied.
      beforeOperateScale - Round other to beforeOperateScale decimal places before doing multiplication.
      返回:
      The calculated instance.
    • divideWithScale

      public CalculationUtil divideWithScale(Number other, Integer scale)
      Calc: the original value divide the other number.
      参数:
      other - The value to be multiplied.
      scale - The result is rounded to scale decimal places.
      返回:
      The calculated instance.
    • divideWithScale

      public CalculationUtil divideWithScale(Number other, Integer scale, Integer beforeOperateScale)
      Calc: the original value divide the other number.
      参数:
      other - The value to be multiplied.
      scale - The result is rounded to scale decimal places.
      beforeOperateScale - Round other to beforeOperateScale decimal places before doing dividing.
      返回:
      The calculated instance.
    • getValue

      public BigDecimal getValue()
      Get the value of the calculation in BigDecimal.
      返回:
      The result of the figure.
    • getValue

      public BigDecimal getValue(int scale)
      Get the value of the calculation in BigDecimal.
      参数:
      scale - The result is rounded to scale decimal places.
      返回:
      The result of the figure.
    • getDouble

      public Double getDouble()
      Get the value of the calculation in Double.
      返回:
      The result of the figure.
    • getDouble

      public Double getDouble(int scale)
      Get the value of the calculation in Double.
      参数:
      scale - The result is rounded to scale decimal places.
      返回:
      The result of the figure.
    • getLong

      public Long getLong()
      Get the value of the calculation in Long.
      返回:
      The result of the figure.
    • getInteger

      public Integer getInteger()
      Get the value of the calculation in Integer.
      返回:
      The result of the figure.