File tree 1 file changed +11
-4
lines changed
1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
+
2
3
/**
3
4
* A class representation of the BSON Double type.
4
5
*/
@@ -41,16 +42,22 @@ class Double {
41
42
if ( options && ( options . legacy || ( options . relaxed && isFinite ( this . value ) ) ) ) {
42
43
return this . value ;
43
44
}
44
- return { $numberDouble : this . value . toString ( ) } ;
45
+
46
+ if ( Object . is ( Math . sign ( this . value ) , - 0 ) ) {
47
+ return { $numberDouble : `-${ this . value . toFixed ( 1 ) } ` } ;
48
+ }
49
+
50
+ return {
51
+ $numberDouble : Number . isInteger ( this . value ) ? this . value . toFixed ( 1 ) : this . value . toString ( )
52
+ } ;
45
53
}
46
54
47
55
/**
48
56
* @ignore
49
57
*/
50
58
static fromExtendedJSON ( doc , options ) {
51
- return options && options . relaxed
52
- ? parseFloat ( doc . $numberDouble )
53
- : new Double ( parseFloat ( doc . $numberDouble ) ) ;
59
+ const doubleValue = parseFloat ( doc . $numberDouble ) ;
60
+ return options && options . relaxed ? doubleValue : new Double ( doubleValue ) ;
54
61
}
55
62
}
56
63
You can’t perform that action at this time.
0 commit comments