---8<---
PROCEDURE Main()
LOCAL a
hb_JsonDecode( '{ "N": 12.123456 }', @a )
? Str( a[ "N" ], 12, 6 ), "Good"
? hb_JsonEncode( a ), "Bad!"
a := { "N" => 12.123456 }
? Str( a[ "N" ], 12, 6 ), "Good"
? hb_JsonEncode( a ), "Good"
hb_JsonDecode( '{ "N": 5e2 }', @a )
? Str( a[ "N" ], 18, 6 ), "Bad!"
? hb_JsonEncode( a ), "Bad!"
hb_JsonDecode( '{ "N": 5e-2 }', @a )
? Str( a[ "N" ], 18, 6 ), "Bad!"
? hb_JsonEncode( a ), "Bad!"
RETURN
Index: hbjson.c
===================================================================
--- hbjson.c (revision 18510)
+++ hbjson.c (working copy)
@@ -481,6 +481,7 @@
HB_MAXINT nValue = 0;
double dblValue = 0;
HB_BOOL fNeg, fDbl = HB_FALSE;
+ int iDec = 0;
fNeg = *szSource == '-';
if( fNeg )
@@ -503,6 +504,7 @@
mult /= 10;
dblValue += ( ( double ) ( *szSource - '0' ) ) * mult;
szSource++;
+ iDec++;
}
}
if( *szSource == 'e' || *szSource == 'E' )
@@ -515,7 +517,6 @@
if( fNegExp )
szSource++;
- szSource++;
while( *szSource >= '0' && *szSource <= '9' )
{
iExp = iExp * 10 + *szSource - '0';
@@ -527,10 +528,12 @@
fDbl = HB_TRUE;
}
dblValue *= pow( 10.0, ( double ) ( fNegExp ? -iExp : iExp ) );
+ if ( fNegExp )
+ iDec += iExp;
}
if( fDbl )
- hb_itemPutND( pValue, fNeg ? -dblValue : dblValue );
+ hb_itemPutNDDec( pValue, fNeg ? -dblValue : dblValue, iDec );
else
hb_itemPutNInt( pValue, fNeg ? -nValue : nValue );
return szSource;
Regards.