Commit d3b43b0b authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Implement AFMakeNumber

Also make stringToNumber be stubborn when converting strings to numbers

CCBUGS: 418445
parent 9084bfaa
......@@ -136,6 +136,16 @@ function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bC
return;
}
function AFMakeNumber(string)
{
var type = typeof string;
if ( type == "number" )
return string;
if ( type != "string" )
return 0;
return util.stringToNumber( string );
}
/** AFTime_Format
*
* Formats event.value based on parameters.
......
......@@ -158,9 +158,10 @@ static KJSObject numberToString ( KJSContext *context, void *,
return KJSString( locale.toString( number, format.toLatin1(), precision ) );
}
/** Converts a String to a Number using l10n.
/** Converts a String to a Number trying with the current locale first and
* if that fails trying with the reverse locale for the decimal separator
*
* Number stringToNumber( String number, String LocaleName = system ) */
* Number stringToNumber( String number ) */
static KJSObject stringToNumber ( KJSContext *context, void *,
const KJSArguments &arguments )
{
......@@ -175,18 +176,18 @@ static KJSObject stringToNumber ( KJSContext *context, void *,
return KJSNumber( 0 );
}
QLocale locale;
if ( arguments.count() == 2 )
{
locale = QLocale( arguments.at( 1 ).toString( context ) );
}
const QLocale locale;
bool ok;
const double converted = locale.toDouble( number, &ok );
double converted = locale.toDouble( number, &ok );
if ( !ok )
{
return KJSNumber( std::nan( "" ) );
const QLocale locale2( locale.decimalPoint() == QLatin1Char('.') ? QStringLiteral("de") : QStringLiteral("en") );
converted = locale2.toDouble( number, &ok );
if ( !ok )
{
return KJSNumber( std::nan( "" ) );
}
}
return KJSNumber( converted );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment