Java Double.compareTo() 方法

2024 年 11 月 10 日 | 阅读 1 分钟

Double 类的 compareTo() 方法按数值比较两个 double 值。

语法

参数

anotherDouble - 要比较的 Double 值

返回值

此方法返回的值为:

  • 零,如果 anotherDouble 与此 Double 的值相同。
  • 正值,如果 anotherDouble 的值大于此 Double 的值。
  • 负值,如果 anotherDouble 的值小于此 Double 的值。

示例 1

输出

10.44 is greater.
Answer after subtraction is= 0.4399999999999995

示例 2

输出

Enter your percentage
48
Congrats you are eligible for the Exam.