mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-23 04:11:54 -04:00
fixes a rounding issue
This commit is contained in:
parent
f0a1b16e9a
commit
c7310eff28
@ -225,9 +225,9 @@ public final class Bits {
|
|||||||
private static long decodeFixed(String str) throws NumberFormatException {
|
private static long decodeFixed(String str) throws NumberFormatException {
|
||||||
int p = str.indexOf(':');
|
int p = str.indexOf(':');
|
||||||
try {
|
try {
|
||||||
int frac = Integer.parseInt(str.substring(p + 1));
|
int frac = Math.abs(Integer.parseInt(str.substring(p + 1)));
|
||||||
double floating = Double.parseDouble(str.substring(0, p));
|
double floating = Double.parseDouble(str.substring(0, p));
|
||||||
return (long) (floating * (1L << frac));
|
return Math.round(floating * (1L << frac));
|
||||||
} catch (java.lang.NumberFormatException e) {
|
} catch (java.lang.NumberFormatException e) {
|
||||||
throw new NumberFormatException(str, 0);
|
throw new NumberFormatException(str, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user