Multiply Floating Point Numbers in Kotlin

thumbnail

In this tutorial, you will learn to multiply two floating point numbers using Kotlin. Then, the result will be displayed on the screen. The program we creating will have two floating point numbers 1.5f and 2.0f. The values will be stored in firstVariable and secondVariable, respectively. Notice, we have used f after the numbers. This ensures. The numbers are Float, otherwise the will be assigned as Double.

The firstVariable and secondVariable are then multiplied using * operator and the result is stored in a new float variable productResult. Finally, the productResult is printed on the screen using println() function.

Example: Multiply Floating Point Numbers in Kotlin

fun main(args: Array<String>) {
    val firstVariable = 1.5f
    val secondVariable = 2.0f
    val productResult = firstVariable * secondVariable
    println("The result is: $productResult")
}

The output will be:

The result is: 3.0

Read More:

Back To Top