Coder Social home page Coder Social logo

jsonbignumber's Introduction

JSONBigNumber

JSONBigNumber.parse/stringify handling all JSON numbers using BigNumber. Based on Douglas Crockford JSON.js package and bignumber.js library.

Build Status Known Vulnerabilities

Usage

All JSON numbers will be passed to BigNumber in the JavaScript object returned from JSONBigNumber.parse()

example

let input = '{"big":1234567890.123456789,"small":789.012}';

let obj1 = JSON.parse(input);
console.log("JSON", obj1.big.toString());  //'JSON', '1234567890.1234567'
//The number has lost the last 2 digits
let out1 = JSON.stringify(obj1);
console.log("JSON", out1);  //'JSON', '{"big":1234567890.1234567,"small":789.012}'

let obj2 = JSONBigNumber.parse(input);
console.log("JSONBigNumber", obj2.big.toString());  //'JSONBigNumber', '1234567890.123456789'
//No loss of precision
let out2 = JSONBigNumber.stringify(obj2);
console.log("JSONBigNumber", out2);  //'JSONBigNumber', '{"big":1234567890.123456789,"small":789.012}'

JSONBigNumber.js: This file creates a JSONBigNumber property in the global object, setting its value to an object containing a stringify method and a parse method. The parse method uses recursive descent to do the parsing.

Note

For bignumber.js >= v6.0.0 use JSONBigNumber >= v1.0.0 For bignumber.js < v6.0.0 use JSONBigNumber < v1.0.0

JSON is a light-weight, language independent, data interchange format. See http://www.JSON.org/

JSON became a built-in feature of JavaScript when the ECMAScript Programming Language Standard - Fifth Edition was adopted by the ECMA General Assembly in December 2009. Unfortunately the built-in JSON handler makes use of JavaScript Number for handling Numbers in JSON causing the loss of precision for numbers with approximately 15 significant figures.

jsonbignumber's People

Contributors

dependabot[bot] avatar douglascrockford avatar wbuss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jsonbignumber's Issues

error in nodejs context

json-bignumber/dist/JSONBigNumber.min.js:1
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("bignumber.js")):"function"==typeof define&&define.amd?define(["bignumber.js"],e):"object"==typeof exports?exports.JSONBigNumber=e(require("bignumber.js")):t.JSONBigNumber=e(t.BigNumber)}(window,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:

ReferenceError: window is not defined
    at Object.<anonymous> (json-bignumber/dist/JSONBigNumber.min.js:1:279)

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.