PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 10, 2022

[FIXED] How can I display a variable in an exponential format with 2 decimals in javascript?

 August 10, 2022     decimal, format, javascript     No comments   

Issue

I am trying to get the right format for my operations, I want an exponential but I would like to limit the number of displayed decimals to only 2, like for example 1.13E+2 how can I do this work? Thanks in advance

row.querySelector(".one").value = (C1 * fuel).toExponential();
row.querySelector(".two").value = (C2 * fuel).toExponential();
row.querySelector(".three").value = (C3 * fuel).toExponential(); 

enter image description here


Solution

You can use toFixed, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

row.querySelector(".one").value = Number.parseFloat((C1 * fuel).toExponential(2));


Answered By - Frank Dax
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing