javascript - Method will roundoff the final sum to 2 decimal places - jquery -


मेरे पास यह कोड है:

  & lt; स्क्रिप्ट & gt; $ (Document) .ready (function () {function compute () {var a = $ ('# a')। Val (); var b = $ ('# b')। Val (); var total = a * B + (8/100) * a; $ ('# total')। Val (कुल);} $ ('# a, #b')। परिवर्तन (गणना);}); & Lt; / script & gt;  

¿के रूप में मैं कमांड (.toFixed) का उपयोग कर सकता हूं? हमेशा गोल प्रदर्शन करने के लिए राशि को दो दशमलव स्थानों पर समाप्त हो जाएगा।

धन्यवाद।

<पी > आप ".toFixed (2)" का उपयोग कर सकते हैं, यह हमेशा दो दशमलव के दौर का होता है हालांकि यह फ्लोट / दशमलव संख्या के स्थान पर एक स्ट्रिंग लौटाएगा।

काम करने के लिए आपके उदाहरण कोड का लिंक देखें


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -