JavaScript में बड़ी संख्याओं को संग्रहीत करने के लिए, + ऑपरेटर के बजाय BigInt() का उपयोग करें। यदि आप + ऑपरेटर का उपयोग करेंगे, तो सटीकता की हानि की अपेक्षा करें।
मान लीजिए निम्नलिखित हमारी बड़ी संख्या है और हम BigInt() का उपयोग करके संग्रहीत कर रहे हैं:
console.log("Loss of precision with + operator..")
उदाहरण
निम्नलिखित कोड देखें:
var stringValue1 = "100";
console.log("The integer value=");
console.log(+stringValue1);
var stringValue2 = "2312123211345545367";
console.log("Loss of precision with + operator..")
console.log(+stringValue2);
const storeLongInteger = BigInt("2312123211345545367");
console.log("No loss of precision with BigInt()");
console.log(storeLongInteger);
उपरोक्त प्रोग्राम चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js.
यहां, मेरा फ़ाइल नाम demo212.js है।
आउटपुट
कंसोल पर आउटपुट इस प्रकार है:
PS C:\Users\Amit\JavaScript-code> node demo213.js The integer value= 100 Loss of precision with + operator.. 2312123211345545000 No loss of precision with BigInt() 2312123211345545367n