-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLR type decimal not working correctly if thread CultureInfo has "," as a decimal separator #97
Comments
- Added basic test cases related to specific numeric types (actually all excepted Integer and Double) that do not work properly when the Current Culture uses a comma as a decimal separator Conflicts: Src/CLR4.sln
The same happens with Single precision floats btw. AFAIK, only Integer and Double CLR numeric types are trated as first-class "Numbers" when they get boxed to BoxedValue thru the SetGlobal call. (see the BoxedValue.Box(object) method) var ctx = new IronJS.Hosting.CSharp.Context();
const float f = 1.5F;
ctx.SetGlobal("myFloat", f);
var result = ctx.GetGlobal("myFloat"); // Result is a "BoxedValue"
Assert.IsTrue(result.IsNumber); // This fails What's even more funny is that for Single precision floats, this could be resolved by avoiding the boxing from float to object that happens somewhere (I don't know exactly where...) when invoking SetGlobal, which eventually prevents the implicit conversion Anyway, that would not solve the problem for decimal values.
So some possible workarounds to this issue :
var ctx = new IronJS.Hosting.CSharp.Context();
const decimal d = 1.5m;
const string globalVariableName = "decimalVal";
ctx.SetGlobal(globalVariableName, d);
var result = ctx.GetGlobalAs<decimal>(globalVariableName);
Assert.AreEqual(d, result);
I'll try to push a fix on my fork within days/weeks. Actually this also concerns my "fr-FR" CurrentCulture :-) |
There is no support in JavaScript for some sort of "decimal" type, which is Regards, On Mon, Mar 4, 2013 at 3:46 PM, Gabriel Boya [email protected]:
|
Yep, I'm aware of that. Yet we should try to keep a consistent behaviour across different CultureInfo. |
I really do not want to intermix Decimal into the JS runtime, floats fine Regards, On Mon, Mar 4, 2013 at 4:05 PM, Gabriel Boya [email protected]:
|
This code seems to fail:
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fi-FI");
var ctx = new IronJS.Hosting.CSharp.Context();
ctx.SetGlobal("decimalVal", 1.5m);
Assert.True(ctx.Execute("decimalVal < 3"), "1.5 should be smaller");
Works ok if the CurrentCulture is something like "en-US" where "." is used as a decimal separator.
The text was updated successfully, but these errors were encountered: