Math Object in TypeScript: Part 3
Before reading this article, please go through the following articles:
Introduction
In this article, I am describing some of the TypeScript math functions.
Floor() Method
Syntax
- floor (number)
Function
- Floor(num: number) {
- var span = document.createElement("span");
- span.innerText = "The Floor value of " + num + " is -> " + Math.floor(num) + "\n";
- document.body.appendChild(span);
- }
Log() Method
In TypeScript the log() method returns the logarithm of a number. By default the number base is E. If the specified number is negative then Nan is returned and if the number is 0 then -Infinity is returned.
- log (number)
Function
- Log(num: number) {
- var span = document.createElement("span");
- span.innerText = "The Logarithm of " + num + " is -> " + Math.log(num) + "\n";
- document.body.appendChild(span);
- }
Round() Method
For example, 4.45 will be rounded down and 4.5 will be rounded up.
Syntax
- round(number)
Function
- Round(num: number) {
- var span = document.createElement("span");
- span.innerText = "The Round value of " + num + " is -> " + Math.round(num);
- document.body.appendChild(span);
- }
Complete Program
Floor_Log_Round.ts



Join the conversation! Your thoughts help the community grow.