Skip to content

Instantly share code, notes, and snippets.

@ljank
Created July 1, 2016 10:36
Show Gist options
  • Save ljank/9e3cb8552c97d511f1bc68d67f178b23 to your computer and use it in GitHub Desktop.
Save ljank/9e3cb8552c97d511f1bc68d67f178b23 to your computer and use it in GitHub Desktop.
JSON.stringify(JSON.parse('{"int":1,"float1":1.1,"float2":2.0}'))
// '{"int":1,"float1":1.1,"float2":2}'
// ^ not float anymore :(
// even potentially useful npm packages are useless:
require("is-float")(1.0) // false
require("number-is-float")(1.0) // false
require('is-funcs/is-float')(1.0) // false
Number.isInteger(1.0) // true
// the reason is known: there's no Integer/Float class, only Number.
// But is there a way to avoid losing types, especially when there
// are other non-node.js services that expect to find floats in incoming
// JSON strings after node.js service have "touched" them?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment