A number is truncated by removing digits[3]. For example, truncating the number 14.784 to three digits yields 14.7. Note that truncating is not the same as rounding.
Number | Truncate to digits | Truncated Number |
---|---|---|
14.87482 | 1 | 10 |
14.87482 | 2 | 14 |
14.87482 | 3 | 14.8 |
14.87482 | 4 | 14.87 |
14.87482 | 5 | 14.8748 |
14.87482 | 6 | 14.87482 |
Table 1: Truncation examples |
In computer languages, to truncate means to convert a floating point or decimal number to an integer[3]. The following code truncates the floating point number 3.62 to the integer 3 and prints '3'.
float num1 = 3.62;
integer num2 = trunc(num1);
print num2
The following code truncates a floating point number 7.2832 to two decimal places and prints '7.28'.
float num1 = 7.2832;
float num2 = trunc(num1 * 100.0) / 100.0;
print num2;
# | A | B | C | D |
E | F | G | H | I |
J | K | L | M | N |
O | P | Q | R | S |
T | U | V | W | X |
Y | Z |
All Math Words Encyclopedia is a service of
Life is a Story Problem LLC.
Copyright © 2018 Life is a Story Problem LLC. All rights reserved.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License