Skip to content

Commit 9be9270

Browse files
committed
feat: implement decimal extraction and rounding logic
1 parent bd483c1 commit 9be9270

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Sprint-1/exercises/decimal.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@ const num = 56.5678;
77
// Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number )
88

99
// Log your variables to the console to check your answers
10+
11+
12+
const wholeNumberPart = Math.floor(num);
13+
console.log(` Whole number = ${wholeNumberPart}`);
14+
15+
const decimalPart = num - wholeNumberPart;
16+
console.log(` Decimal part = ${decimalPart.toFixed(4)}`); // toFixed(4) to show 4 decimal places instead of whole number
17+
18+
console.log(typeof(wholeNumberPart)); //confirm that decimalPart is a number
19+
20+
const roundedNum = Math.round(num);
21+
console.log(` Rounded number = ${roundedNum}`);

0 commit comments

Comments
 (0)