Type Conversion

Last Updated : 15 Oct, 2026

Given a double value d, typecast it to an integer value and print it.

Examples:

Input: d = 10.23
Output: 10
Explanation: The integer value of 10.23 is 10

Input: d = 19.1
Output: 19

Extra Variable

The idea is to convert the given double value into an integer using typecasting and store the result in a separate variable.

Working of Approach:

  • Read the double value d.
  • Typecast d to an integer using (int)d.
  • Store the converted value in a variable result.
  • Print result as the output.
C++
#include <iostream>
using namespace std;

int main()
{
    double d = 10.23;

    // Convert the double value to an integer
    int res = (int)d;

    // Print the converted integer value
    cout << res << endl;

    return 0;
}
Java
public class GFG {
    public static void main(String[] args)
    {
        double d = 10.23;

        // Convert the double value to an integer
        int res = (int)d;

        // Print the converted integer value
        System.out.println(res);
    }
}
Python
d = 10.23

# Convert the double value to an integer
res = int(d)

# Print the converted integer value
print(res)
C#
using System;

class GFG {
    static void Main()
    {
        double d = 10.23;

        // Convert the double value to an integer
        int res = (int)d;

        // Print the converted integer value
        Console.WriteLine(res);
    }
}
JavaScript
let d = 10.23;

// Convert the double value to an integer
let res = Math.floor(d);

// Print the converted integer value
console.log(res);

Output
10

Typecasting

The idea is to convert the given double value into an integer using typecasting and print the result directly.

Working of Approach:

  • Read the given double value d.
  • Convert d into an integer using typecasting.
  • The fractional part of the value is discarded during conversion.
  • Print the resulting integer value directly.
C++
#include <iostream>
using namespace std;

int main()
{
    double d = 10.23;

    // Convert the double value to an integer and print it
    cout << static_cast<int>(d) << endl;

    return 0;
}
Java
public class GFG {
    public static void main(String[] args)
    {
        double d = 10.23;

        // Convert the double value to an integer and print
        // it
        System.out.println((int)d);
    }
}
Python
d = 10.23

# Convert the double value to an integer and print it
print(int(d))
C#
using System;

class GFG {
    static void Main()
    {
        double d = 10.23;

        // Convert the double value to an integer and print
        // it
        Console.WriteLine((int)d);
    }
}
JavaScript
let d = 10.23;

// Convert the double value to an integer and print it
console.log(Math.floor(d));

Output
10
Comment