Skip to main content

AsDouble

property AsDouble: Double read write;

Example

procedure ScriptEvent(var Value: variant);
var
Text: TJSONString;
Item: TJSONValue;
begin
Text := TJSONString.Create;
try
Item := Text;
Item.AsString := '12.5';
Value := Item.AsDouble;
finally
Text.Free;
end;
end;

Usage

AsDouble performs strict locale-sensitive floating conversion and writes formatted Double text through the value class.

Additional Technical Info

The reader returns 0.0 for a null value. Otherwise it passes AsString to the no-format-settings Delphi StrToFloat overload and returns the result narrowed to Double. Invalid Boolean, structured or numeric text raises EConvertError; leading/trailing blanks are accepted by Delphi.

The selected overload uses the process/thread global decimal separator. JSON requires a period, but this property neither enforces JSON number grammar nor supplies invariant settings. A period-form input can fail in a comma-decimal environment, while comma text can be accepted even though it is not a JSON number. The global-settings overload is documented as not thread-safe.

Writing calls the no-format-settings FloatToStr, then routes that locale-sensitive text through the concrete virtual String setter. On a TJSONDouble it parses back under the same current settings; on TJSONString it stores the locale form as text. A Boolean or integer can reject/range-fail, and a container interprets the text as a replacement document. Formatting can also lose binary64 detail under the Deltics/Delphi formatting path and can emit non-JSON representations for non-finite values.

Use AsFloat0 only when conversion failure must deliberately collapse to zero. Use AsFloat as the exact Velox alias of this property. Neither alias distinguishes null from numeric zero without IsNull.

External references

Created 2026-07-15