我正在使用jQuery Globalize插件以及jQuery验证。
对于有效的瑞典号5.000,00
,parseFloat函数给出NaN
以下代码/库中的错误是什么?
<script type="text/javascript" src="/Scripts/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="/Scripts/globalize.js"></script>
<script type="text/javascript" src="/Scripts/cultures/globalize.culture.sv.js"></script>
<script type="text/javascript" src="/Scripts/jquery.validate.js"></script>
<script type="text/javascript" src="/Scripts/jquery.validate.unobtrusive.js" ></script>
<script type="text/javascript">
jQuery(function () {
Globalize.culture('sv');
$.validator.methods.number = function (value, element) {
if (Globalize.parseFloat(value)) { // this gives NaN
return true;
}
return false;
}
});
</script>
答案 0 :(得分:2)
我认为你使用的是错误的文化。或者您的输入数字格式错误。 http://jsfiddle.net/98sgm/1/
jQuery(function () {
Globalize.culture('sv');
alert(Globalize.parseFloat('5.000,00'));
alert(Globalize.parseFloat('5,000.00'));
});
来自文化文件的源代码:
numberFormat: {
",": " ",
".": ",",
negativeInfinity: "-INF",
positiveInfinity: "INF",
percent: {
",": " ",
".": ","
},
currency: {
pattern: ["-n $","n $"],
",": ".",
".": ",",
symbol: "kr"
}
},
编辑: 创建新的区域性文件并将numberFormat选项设置为以下内容:
numberFormat: {
",": ".",
".": ",",
negativeInfinity: "-INF",
positiveInfinity: "INF",
percent: {
",": " ",
".": ","
},
currency: {
pattern: ["-n $","n $"],
",": ".",
".": ",",
symbol: "kr"
}
},
答案 1 :(得分:0)
瑞典实际上将空间用作千分隔符。 我找不到一个非常好的参考。 (我是瑞典人,1 000 000,123看起来比我好1.000.000,123)
以下.NET C#代码接缝进行确认。
Console.WriteLine(String.Format("'{0}'", System.Globalization.CultureInfo.GetCultureInfo("sv-SE").NumberFormat.NumberGroupSeparator));
此外,如果您转到“区域和语言”,然后在Windows中选择“其他设置”并选择瑞典语(瑞典),则会将数字分组符号显示为空格。
oracle接受同意: http://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html