Jump to content
Davide Angeli

ISuperObject decimal issue with currency values

Recommended Posts

I have a problem that's driving me crazy. I'm using ISuperObject to store in a JSON string a series of complex (non-tabular) data in a Firebird memo field. Within this JSON, some numerical data with two decimal places (which are currency type variables in Delphi) is being stored.

In a couple of cases (which I unfortunately can't replicate myself with the same values), some of my customers, upon saving this data, ended up with more than two decimal places in the resulting JSON (for example, 2332.89 became 2332.889xxxx).

I'm using the ISuperObject property like this O.F['namevar']:=currencyvalue to insert the data into the JSON. Do you think it's possible that the behavior of ISuperObject might vary on certain computers, leading to the problem I've encountered?

Share this post


Link to post

In my experience this will be due to Locale differences - does superobject use FormatSettings at all? 

Share this post


Link to post
13 minutes ago, Vincent Parrett said:

In my experience this will be due to Locale differences - does superobject use FormatSettings at all? 

procedure TJSONFloat.AsJSONString(Str: TJSONWriter);
begin
  if FNull then
     Str.AppendVal( cNull )
  else
     Str.AppendVal( FloatToStr(Value, FloatFormat) );
end;

 

Share this post


Link to post
Just now, Vincent Parrett said:

What is FloatFormat set to?

const
  FloatFormat : TFormatSettings = ( DecimalSeparator : '.' );

 

Share this post


Link to post
1 minute ago, Stefan Glienke said:

If it is currency, then FloatToStr is wrong to begin with

I agree. Unfortunately, ISuperObject does not support the direct insertion of currency type data.

Share this post


Link to post

The ICS component library includes a fork of SuperObject, with various bug features and new features, including returning parsing errors and support for Delphi TDateTime, saved as
an ISO 8601/RFC3339 string:  obj.AsDateTime,  obj.AsObject.DT['foo']

 

https://svn.overbyte.be/svn/icsv9/Source/OverbyteIcsSuperObject.pas

 

I could add a currency type if useful. .  

 

Angus

 

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×