Recent

Author Topic: TJsonObject | Number Value Problem  (Read 2333 times)

cpalx

  • Hero Member
  • *****
  • Posts: 753
TJsonObject | Number Value Problem
« on: September 25, 2018, 03:05:44 pm »
Hello
i am using lazarus 1.8.4 (FPC 3.04)

i am using TjsonObject and i add a number, for example

Code: Pascal  [Select][+][-]
  1. var x: Real;
  2.      jo: TjsonObject;
  3. begin
  4.   x:= 5;
  5.    jo:= tjsonobject.create;
  6.    jo.add( 'x', x );
  7.    writeln( jo.AsJson )
  8. end;

and return

{"x" : 5.0000000000000000E+000}

how can i do for not show scientific notation?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TJsonObject | Number Value Problem
« Reply #1 on: September 25, 2018, 06:10:04 pm »
Code: Pascal  [Select][+][-]
  1. var
  2.   x: TJSONFloat = 5.21;
  3.   jo: TJSONFloatNumber;
  4. begin
  5.   jo := TJSONFloatNumber.Create(x);
  6.   WriteLn(jo.AsFloat:5:2);
  7.   jo.Free;
  8. end;

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TJsonObject | Number Value Problem
« Reply #2 on: September 25, 2018, 11:04:15 pm »
Also the procedure "str" can be used to create a string of the same output but without sending it to the
stream.

 Str(jo.AsJson,5:2, MyOutPutString);
The only true wisdom is knowing you know nothing

cpalx

  • Hero Member
  • *****
  • Posts: 753
Re: TJsonObject | Number Value Problem
« Reply #3 on: September 27, 2018, 03:15:49 am »
Thanks

 

TinyPortal © 2005-2018