Javascript Bigdecimal Example - Javascript

How to use bigdecimal method in javascript?

Snippet Code


  
Rate this page :
  [ 0 votes]

The bigdecimal in java is a class which provides the operations for rounding, hasing and comparison. This javascript code which helps you to avoid rounding errors by using bigdecimal method. To run this code you need to install BigDecimal-all-last.min.js file.

<script src='https://raw.githubusercontent.com/dtrebbien/BigDecimal.js/master/build/BigDecimal-all-last.min.js'></script> <script type='text/javascript'> document.write("0.1 + 0.2 = "); document.write("</br>Javascript Output :: "); document.write(0.1 + 0.2); document.write("</br>BigDecimal Output :: "); document.write((new BigDecimal("0.1")).add(new BigDecimal("0.2"))); document.write("</br></br></br>345.4567890 * 123456789.123456789987654321 = "); document.write("</br>Javascript Output :: "); document.write(345.4567890*123456789.123456789987654321); document.write("</br>BigDecimal Output :: "); document.write((new BigDecimal("345.4567890")).multiply(new BigDecimal("123456789.123456789987654321"))); </script>

Tags


Ask Questions

Ask Question