Kotlin math truncate() function with examples

Updated

The Math.truncate() function used to return the rounded value of the specified double and float value.

Syntax: fun truncate(x : DataType): DataType
Parameters: It can take data two data type such as Double and Float.
Returns: It returns the rounded value of the specified double and float value.

Code #1: Taking float data types as argument.

// Kotlin program to illustrate
// working of Math.truncate() method 
import kotlin.math.truncate

fun main(args : Array<String>){

    val float1 = 42.23f;
    val float2 = 46.99f;
    val float3 = 49.00f;
  
    // Calling the tuncate() function
    println(truncate(float1));
    println(truncate(float2));
    println(truncate(float3));
}

Output :

42.0
46.0
49.0

Code #2: Taking double data types as argument.

// Kotlin program to illustrate
// working of Math.truncate() method 
import kotlin.math.truncate

fun main(args : Array<String>){

    val Double1 = 12.23;
    val Double2 = 22.99;
    val Double3 = 34.00;
  
    // Calling the tuncate() function
    println(truncate(Double1));
    println(truncate(Double2));
    println(truncate(Double3));
}

Output :

12.0
22.0
34.0
Comment
Next tutorial
Mithlesh Upadhyay Published 8 Nov 2026 · 1 min read

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.

Related tutorials