Thursday, September 4, 2025
HomeLanguagesJavascriptHow to add float numbers using JavaScript ?

How to add float numbers using JavaScript ?

Given two or more numbers and the task is to get the float addition in the desired format with the help of JavaScript. There are two methods to solve this problem which are discussed below:

 Approach 1:

Example: This example implements the above approach. 

Javascript




let val = parseFloat('2.3') + parseFloat('2.4');
console.log("2.3 + 2.4 = " + val);
 
function gfg_Run() {
    console.log("2.3 + 2.4 = "
        + (parseFloat('2.3') +
            parseFloat('2.4')).toFixed(2));
}
gfg_Run()


Output

2.3 + 2.4 = 4.699999999999999
2.3 + 2.4 = 4.70

Approach 2:

Example: This example implements the above approach. 

Javascript




let val = parseFloat('2.3') + parseFloat('2.4');
console.log("2.3 + 2.4 = " + val);
 
function gfg_Run() {
    console.log("2.3 + 2.4 = " +
        Math.round((parseFloat('2.3')
            + parseFloat('2.4')) * 100) / 100);
}
gfg_Run()


Output

2.3 + 2.4 = 4.699999999999999
2.3 + 2.4 = 4.7
RELATED ARTICLES

Most Popular

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6627 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS