TRUNC Function – Truncate in Excel, VBA, & Google Sheets
This tutorial demonstrates how to use the Excel TRUNC Function in Excel to truncate a number.
TRUNC Function Overview
The TRUNC Function Truncates a number to a specific number of digits.
To use the TRUNC Excel Worksheet Function, select a cell and type:
(Notice how the formula inputs appear)
TRUNC Function Syntax and Inputs:
=TRUNC(number,num_digits)
number – A number.
num_digits – The number of decimal places you want remaining after you truncate. Zero for none. Negative will truncate to the left of the decimal place.
TRUNC Examples in VBA
TRUNC is not a member of the application.worksheetfunction. Because of this, it cannot be used the same way from within Excel VBA. Instead, we can use the FORMAT function, which will create the same result, as follows:
Executing the following VBA statements
Range("B2") = Format(Range("A2"), "##,##0.0000")
Range("B3") = Format(Range("A3"), "##,##0.000")
Range("B4") = Format(Range("A4"), "##,##0.00")
Range("B5") = Format(Range("A5"), "##,##0.00")
Range("B6") = Format(Range("A6"), "##,##0")
will produce the following results
For the function arguments (number, etc.), you can either enter them directly into the function, or define variables to use instead.