存储浮点值[重复]

 收藏

What is the proper way to increase a float number in wit with some percent? In my case when I have 120.33 which I want to increase it with 3%.

我尝试了这个:

class Main {
  public static void main(String[] args) {

    float originalValue = 120.33;
    int increasePercent = 3;

    float increasedNumber;

    increasedNumber = originalValue * ((100 + increasePercent) / 100);

    System.out.println(increasedNumber);
  }
}

But I get: incompatible types: possible lossy conversion from double to float

声明此值的正确方法是什么?

回复