Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

JavaScript Truncate

by suresh

The JavaScript Truncate function (trunc(x)) is a Math function. The Truncate function is used to remove the decimal values from specified expression and return the integer value. The syntax of the JavaScript Truncate Function is:

Math.trunc(number);

Number: It can be a decimal or a numerical expression

  • If the number argument is a positive or negative number, JS truncate function will return the truncated value.
  • If it is not a number, the trunc function will return NaN.
  • And if it is Null, the trunc function will return Zero.

JavaScript Truncate Function Example

The JavaScript Truncate Function removes the decimal values and returns the integer value. In this Truncate example, We are going to find the truncated values of different data types using trunc() and display the output

  • First, we used the trunc Function on the Positive Decimal values.
  • Next two statements, We used the JavaScript trunc Function on the negative Decimal values.
  • Next, we tried trunc Function on the string value. It will return NaN (Not a Number) as output
  • Last, we tried JS truncate Math function on Null value and it returns Zero
<!DOCTYPE html>
<html>
<head>
    <title> JavaScript TRUNCATE Function </title>
</head>
<body>
  <h1> JavaScript TRUNC Function </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Null"></p>
  <script>
    document.getElementById("Pos").innerHTML = Math.trunc(10.95);
    document.getElementById("Dec").innerHTML = Math.trunc(10.05);
    document.getElementById("Neg").innerHTML = Math.trunc(-14.95);
    document.getElementById("Neg_Dec").innerHTML = Math.trunc(-14.05);
    document.getElementById("Str").innerHTML = Math.trunc("JavaScript");
    document.getElementById("Null").innerHTML = Math.trunc(null);
  </script>
</body>
</html>
JavaScript TRUNCATE Function

Placed Under: JavaScript

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021· All Rights Reserved.
About | Contact | Privacy Policy