diff --git a/core/script/builtin.js b/core/script/builtin.js index 9a116c4bf..6686873fd 100644 --- a/core/script/builtin.js +++ b/core/script/builtin.js @@ -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. diff --git a/core/script/kjs_util.cpp b/core/script/kjs_util.cpp index 9d5e46ed6..1e1382fd1 100644 --- a/core/script/kjs_util.cpp +++ b/core/script/kjs_util.cpp @@ -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 );