-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber.html
More file actions
43 lines (36 loc) · 1.21 KB
/
number.html
File metadata and controls
43 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Number Methods</title>
<script>
function demonstrateNumberMethods() {
var number = 123.456;
// Convert to string with specific decimal places
var formattedNumber = number.toFixed(2);
// Convert to exponential notation
var exponentialNumber = number.toExponential(3);
// Get the integer part of the number
var integerPart = Math.floor(number);
// Get the floating-point part of the number
var fractionalPart = number - integerPart;
// Get the absolute value
var absoluteValue = Math.abs(-7.89);
var output = `
Original Number: ${number} <br>
Formatted Number (toFixed): ${formattedNumber} <br>
Exponential Notation (toExponential): ${exponentialNumber} <br>
Integer Part (Math.floor): ${integerPart} <br>
Fractional Part: ${fractionalPart} <br>
Absolute Value (Math.abs): ${absoluteValue}
`;
document.getElementById("output").innerHTML = output;
}
</script>
</head>
<body>
<button onclick="demonstrateNumberMethods()">Show Number Methods</button>
<p id="output"></p>
</body>
</html>