Code Review
/
yangtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Fix Decimal64.toString()
[yangtools.git]
/
common
/
yang-common
/
src
/
main
/
java
/
org
/
opendaylight
/
yangtools
/
yang
/
common
/
Decimal64.java
diff --git
a/common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Decimal64.java
b/common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Decimal64.java
index c91e42f417935de228eca5f743cfbb06747c1c9b..bd62d8aaaac706d283ce91336bc246a0ad9691fe 100644
(file)
--- a/
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Decimal64.java
+++ b/
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Decimal64.java
@@
-448,11
+448,18
@@
public class Decimal64 extends Number implements CanonicalValue<Decimal64> {
// prohibited, subject to the rule that there MUST be at least one digit
// before and after the decimal point. The value zero is represented as
// "0.0".
// prohibited, subject to the rule that there MUST be at least one digit
// before and after the decimal point. The value zero is represented as
// "0.0".
- final StringBuilder sb = new StringBuilder(21).append(intPart()).append('.');
+
+ final long intPart = intPart();
final long fracPart = fracPart();
final long fracPart = fracPart();
+ final StringBuilder sb = new StringBuilder(21);
+ if (intPart == 0 && fracPart < 0) {
+ sb.append('-');
+ }
+ sb.append(intPart).append('.');
+
if (fracPart != 0) {
// We may need to zero-pad the fraction part
if (fracPart != 0) {
// We may need to zero-pad the fraction part
- sb.append(Strings.padStart(Long.toString(
fracPart
), scale(), '0'));
+ sb.append(Strings.padStart(Long.toString(
Math.abs(fracPart)
), scale(), '0'));
} else {
sb.append('0');
}
} else {
sb.append('0');
}
@@
-502,7
+509,7
@@
public class Decimal64 extends Number implements CanonicalValue<Decimal64> {
}
private long fracPart() {
}
private long fracPart() {
- return
Math.abs(value % FACTOR[offset])
;
+ return
value % FACTOR[offset]
;
}
private static byte offsetOf(final int scale) {
}
private static byte offsetOf(final int scale) {