#1 2024-10-01 03:27:28

bigheart
Member
Registered: 2014-08-01
Posts: 51

Float value is converted to different from original with IDocDict

Hi all,

when i try to convert the float value in IDocDict, the value is returned as added 0.

  LDict := DocDict('{"FloatVal": 24.4}');
  ShowMessage(LDict.S['FloatVal']);

the value is displayed as "24.40" not "24.4".

Please give me some advice how to get the exact value using .S[] function.

Offline

#2 2024-10-01 06:19:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,552
Website

Re: Float value is converted to different from original with IDocDict

The value is stored as variant, and in the variant it is stored as varCurrency.
If the default conversion to text does not please you, the easiest is to use the system conversion.

So you could just write:

 ShowMessage(LDict['FloatVal']);

In fact, LDict['FloatVal'] returns a variant, which is converted to string by the RTL as you expect.

Note that LDict.ToJson() works as you expect.
See https://github.com/synopse/mORMot2/commit/8e5c2152

Offline

Board footer

Powered by FluxBB