Class Calculator

java.lang.Object
com.luna.common.text.Calculator

public class Calculator extends Object
数学表达式计算工具类
见:https://github.com/looly/hutool/issues/1090#issuecomment-693750140
Since:
5.4.3
Author:
trainliang, looly
  • Constructor Details

    • Calculator

      public Calculator()
  • Method Details

    • conversion

      public static double conversion(String expression)
      计算表达式的值
      Parameters:
      expression - 表达式
      Returns:
      计算结果
    • getPrintSize

      public static String getPrintSize(long size)
      字节转kb/mb/gb
      Parameters:
      size -
      Returns:
    • calculate

      public double calculate(String expression)
      按照给定的表达式计算
      Parameters:
      expression - 要计算的表达式例如:5+12*(3+5)/7
      Returns:
      计算结果
    • compare

      public boolean compare(char cur, char peek)
      利用ASCII码-40做下标去算术符号优先级
      Parameters:
      cur - 下标
      peek - peek
      Returns:
      优先级