Im trying to create a plugin for Webuilder which needs to process floating point values, but it turns out to be a real pain.
Example:
- Code: Select all
var teststring = _t( 7/3 );
var testfloat = StrToFloat(teststring);
Script.Message(unitMatch);
Script.Message(_t(fl));
On Windows 8.1, both of these gives me this value: 2,33333333333333
Notice the decimal separator used is a COMMA, not a PERIOD.
While on Windows 7, I get the value: 2.33333333333333
Notice the decimal separator used is a PERIOD.
So how to use floating point values in a plugin?
Currently I do something like this:
- Code: Select all
// Create a floating point number and remove the digits to get the decimal seperator.
var decimalSeparator = RegexReplace(_t(5/2), "\\d*", "", true);
And then replace the decimal seperator before converting string values to floating point.
- Code: Select all
StrToFloat(Replace(floatString, ".", decimalSeparator));
But there must be a better way, and force PERIOD to be the decimal separator?
According to the Delphi docs, you can add a 2nd parameter to StrToFloat().
But this parameter (TFormatSettings) is an object, and AFIK it's not possible to create objects in Webuilder plugins.
Program used: WeBuilder 2015 v13.2.0.164