
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to add float numbers using JavaScript?
In this article, you will understand how to add float numbers using JavaScript. Float values in JavaScript are defined as parseFloat(string).
Example 1
In this example, let’s understand adding float values without using functions.
let inputFloat1 = parseFloat(2.3) let inputFloat2 = parseFloat(3.5) console.log("The two float values are defined as ", inputFloat1 ,"and", inputFloat2) let result = inputFloat1 + inputFloat2 console.log("
The sum of the float values is: ",result)
Explanation
Step 1 − Define two float values inputFloat1 and inputFloat2.
Step 2 − Add the two float values using addition operator (+).
Step 3 − Display the result.
Example 2
In this example, let’s understand adding float values without using functions.
function addFloat(inputFloat1, inputFloat2){ let result = inputFloat1 + inputFloat2 console.log("
The sum of the float values is: ",result) } let inputFloat1 = parseFloat(2.3) let inputFloat2 = parseFloat(3.5) console.log("The two float values are defined as ", inputFloat1 ,"and", inputFloat2) addFloat(inputFloat1, inputFloat2)
Explanation
Step 1 − Define two float values inputFloat1 and inputFloat2.
Step 2 − Define a function addFloat that takes two float values as parameters.
Step 3 − In the function, add the two float values using the addition operator (+).
Step 4 − Display the result.
- Related Articles
- How to add binary numbers using Python?
- How to add/subtract large numbers using Python?
- How to add separator to numbers using MySQL views?
- How to format a float in JavaScript?
- How to add HTML elements dynamically using JavaScript?
- How to add bootstrap toggle-switch using JavaScript?
- Modulus of two float or double numbers using C
- How to convert string into float in JavaScript?
- Haskell Program to get the remainder of float numbers using library function
- Golang Program to get the remainder of float numbers using library function
- Swift program to get the remainder of float numbers using library function
- How to add content in section using jQuery/JavaScript?
- How to add fade-out effect using pure JavaScript?
- How to add fade-in effect using pure JavaScript?
- How to add rows to a table using JavaScript DOM?

Advertisements