Coder Social home page Coder Social logo

Comments (4)

RobThree avatar RobThree commented on August 18, 2024 1

Oh, hahah! I get it. This is actually mentioned in our FAQ:

FAQ

Q: I'm experiencing weird results when these ID's are used in Javascript?

A: Remember that generated ID's are 64 (actually 63) bits wide. Javascript uses floats to store all numbers and the maximum integer value you can safely store is 53 bits. If you need to handle these ID's in Javascript, treat them as strings.

The problem is with Swagger / Json interpreting the ID's as doubles. Look at the actual response:

image

There's nobody at fault here really, it's just the way browsers/JS handle numbers (as described in our FAQ). The values you see are "rounded" to the nearest 53-bit float. If you don't want this to happen then, in a browser context, you should convert your ID's to strings:

[HttpGet("GetIds")]
public ActionResult GetIds(int idCount)
{
    return Ok(_idGenerator.Take(idCount).Select(i => i.ToString()));
}

image

from idgen.

RobThree avatar RobThree commented on August 18, 2024

I have no idea, it works for me when I use it directly and when I get it from DI (which shouldn't make a difference anyway).

Is there something else worth mentioning about your project that might be relevant?

from idgen.

andrew2558 avatar andrew2558 commented on August 18, 2024

thanks, @RobThree
The above is the whole code, I don't know what went wrong
The attachment is the test code, which also has the same problem.

IdGenTest.zip

from idgen.

andrew2558 avatar andrew2558 commented on August 18, 2024

Thank your very much @RobThree

from idgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.