polytronicgr / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Math.Truncate rounds to string #335

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The behaviour of System.Math.Truncate when generated to JavaScript is not 
consistent with .net.

        public static void TestTruncate()
        {
            new jQuery(HtmlContext.document.body).append("1.4 truncated: " + System.Math.Truncate(1.4) + "<br/>");
            new jQuery(HtmlContext.document.body).append("1.6 truncated: " + System.Math.Truncate(1.6) + "<br/>");
            new jQuery(HtmlContext.document.body).append("-1.4 truncated: " + System.Math.Truncate(-1.4) + "<br/>");
            new jQuery(HtmlContext.document.body).append("-1.6 truncated: " + System.Math.Truncate(-1.6) + "<br/>");
            new jQuery(HtmlContext.document.body).append("Type of 1.2 truncated: " + System.Math.Truncate(1.2).GetType() + "<br/>");
        }

This results in:

1.4 truncated: 1
1.6 truncated: 2
-1.4 truncated: -1
-1.6 truncated: -2
Type of 1.2 truncated: {Name = String FullName = System.String}

There are two issues. First it's rounding rather than truncating. Secondly it's 
turning the output in a string.

To confirm it's definitely a string, with the console:

typeof(System.Math.Truncate$$Double(1.2))
"string"

Original issue reported on code.google.com by co...@gravill.com on 5 Dec 2013 at 1:48

GoogleCodeExporter commented 8 years ago

Original comment by DanelK...@gmail.com on 5 Dec 2013 at 2:33

GoogleCodeExporter commented 8 years ago
Fixed - implemented using |0

Original comment by DanelK...@gmail.com on 12 Feb 2014 at 12:18