Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is my code: 

price_result = parseFloat(test_var.split('$')[1].slice(0,-1));

I want to add two decimal places when price_result = integer. For example, if it’s 10, the output should be 10.00. Can anyone tell me how to implement it? 

1 Answer

0 votes
by (19.7k points)

Try toFixed(). See the code implementation below: 

var decimalTwo = parseFloat(yourString).toFixed(2)

If you want to learn more about Javathen go through this Java tutorial by Intellipaat for more insights. 

Related questions

0 votes
1 answer
asked Apr 14, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...