// The given input
String input = "99999999.99";
// We need only 2 decimals (in case of more than 2 decimals is in input)
Float value = Float.valueOf(input);
DecimalFormat df = new DecimalFormat("#0.00");
input = df.format(value);
value = new Float(input);
// Now we have a clear 2 decimal float value
// Check for overflow
value *= 100; // Multiply by 100, because we're working with cents
if (value >= Integer.MAX_VALUE) {
System.out.println("Invalid value");
}
else {
///
}
ステートメントが機能せず、条件が失敗します。浮動小数点値がInteger.MAX_VALUEより大きいかどうかを知る方法?
floatと整数値を比較する正しい方法はどれですか?
注意を持っています。あなたがお金を処理している場合は、可能であれば浮動小数点数の使用を避けるべきです。 –