1

I am using Asp.net MVC and my c ontroller return simple class which is contain properties of ulong type. However value of ulong is not displayed correctly.

For example:

My ulong acutal value is 525623822633172993 but this is displayed 525623822633173000. I could not understand why this problem occurs.

Test Class:

class testClass
        {
            public ulong testUlong = 525623822633172993;
        }

Action Result:

public ActionResult test()
        {
            testClass tssc = new testClass();

            return Json(tssc, JsonRequestBehavior.AllowGet);
        }

Screenshots from Google Chrome Developer tools. (actually value is displayed correctly in Response Tab but it is displayed incorrectly in Preview tab.)

enter image description here enter image description here

How can I display correctly this value?

Thank you.

Community
  • 1
  • 1
Dreamcatcher
  • 798
  • 13
  • 31
  • 1
    Your problem is that the number is too big for Javascript to accurately represent. For example, try this in the console: `var a = 525623822633172993; console.log(a)`. You'll get the same result. Your best bet is to probably send the number as a string. – Matt Burland Oct 24 '14 at 19:04
  • May be it is related to browser console, try `console.log(525623822633172993)` and you will get`714341252076979100` – Habib Oct 24 '14 at 19:04
  • This [SO][1] may help you to understand what you are experiencing [1]: http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript – mreyeros Oct 24 '14 at 19:06
  • Also see: [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER). In chrome it gives me `9007199254740991` which is less than your number. There are JS libraries out there for dealing with large numbers if you actually need to do math with them, but you'll probably still need to send it as a string and then convert it. – Matt Burland Oct 24 '14 at 19:06

0 Answers0