JavaScript DHTML/Dojo toolkit/Currency Format

Материал из Web эксперт
Перейти к: навигация, поиск

Format currency

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/"
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
  </head>
  <body>
    <script language="JavaScript" type="text/javascript">
      dojo.require("dojo.currency");
      document.write(dojo.currency.format(123456789.0123, null));
    </script>
  </body>
</html>



Format numner as currency

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/"
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script language="JavaScript" type="text/javascript">
      dojo.require("dojo.number");
      document.write(dojo.number.format(new Number(1234.56),{ pattern : "$#,###.##", places : 4 }));
    </script>
  </head>
  <body></body>
</html>



Parse currency

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/"
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
  </head>
  <body>
    <script language="JavaScript" type="text/javascript">
      dojo.require("dojo.currency");
      alert(dojo.number.parse("12,345.678", null) + 1);
    </script>
  </body>
</html>