How Close is the Javascript Math.Round to the C# Math.Round? -
By reading I know that the complainants will see your number, decide whether the midpoint is an or odd number and then back Even numbers Example was 2.5, which was round for 3. I have tried to see my small experiments what happens, but I have not got any specific details about this, or even it is consistent between browsers.
$ (document) .ready (function () {$ ("# answer"). Html (showRounding ());}); Function sounding () {var answer = Math.round (2.5); Answer to return; }
This gives a '3'.
What I want to know is this: How closely is the equivalent of C # in Javascript? The reason for this is that I would like to take a javascript method that uses Math.Round
and rewrites the same method in C # and I would like to know that I can get it from a number The result after rounding up
Here is the code for Math.round (x) :
returns 15.8.2.15 round (x) number value which is equivalent to the closest and mathematical integer of x. If two integer values are equal to x, then the result is a number value that is closer to + closer. If X is already an integer, then the result is x.
- If x is nan, the result is nan.
- If x is +0, then the result is +0.
- If x is -0, then the result is -0.
- If x is + ∞, then the result is + ∞.
- If X is - ∞, the result is -∞.
- If X is greater than 0 but less than 0.5, then the result is + 0.
- If x is less than 0 but greater or equal to -0.5, result is -0.
Note 1 Math. (3.5) returns 4, but mathematical (-3.5) return -3
Note 2 The value of the monastery (x) is similar to the value of the monastery. Floor (X + 0.5), when x is less than 0 or 0 or 0, but greater than or equal to 0; Mathrade (X) Returns -0 for these cases, but Math. Floor (X + 0.5) returns + 0 returns.
does not define a particular golfing algorithm. The closest thing we have to do is documentation for .NET. With that, you can see that some javascript cases are not applicable ( Math.Round
handles only decimal and doubles, not countless), and overload of the method gives you more control over the result - You can specify the number of partial digits and midpoint round method in the result. By default, Math.Round
uses 'round the banker'.
Comments
Post a Comment