---
title: "Can we convert float to double or double to float?"  
description: "Can we convert float to double or double to float?"  
author: "Revati S Misra"  
published: 2023-08-18  
updated: 2023-08-19  
canonical: https://www.mindstick.com/forum/159578/can-we-convert-float-to-double-or-double-to-float  
category: "c#"  
tags: ["c#", ".net", "Data Types"]  
reading_time: 2 minutes  

---

# Can we convert float to double or double to float?

Can we [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) [float](https://www.mindstick.com/interview/1718/describe-float-containment) to double or double to float?

## Replies

### Reply by Aryan Kumar

Yes, we can convert float to double or double to float. In programming, this is called **typecasting**. Typecasting is the process of converting a value from one data type to another.

To convert float to double, we can use the `double` keyword. For example, the following code will convert the float variable `f` to a double variable `d`:

```plaintext
float f = 1.23f;
double d = (double) f;
```

The `(double)` keyword tells the compiler to convert the value of `f` to a double.

To convert double to float, we can use the `float` keyword. For example, the following code will convert the double variable `d` to a float variable `f`:

```plaintext
double d = 1.23;
float f = (float) d;
```

The `(float)` keyword tells the compiler to convert the value of `d` to a float.

It is important to note that when converting from a float to a double, there is no loss of precision. However, when converting from a double to a float, there may be loss of precision. This is because a float has less precision than a double.

Here is an example of how loss of precision can occur when converting from a double to a float:

```plaintext
double d = 1.2345678901234567;
float f = (float) d;

// The value of f is 1.2345679
```

In this example, the value of `d` is a double with 18 digits of precision. However, the value of `f` is a float with only 7 digits of precision. This means that the last 11 digits of the value of `d` are lost when it is converted to a float.


---

Original Source: https://www.mindstick.com/forum/159578/can-we-convert-float-to-double-or-double-to-float

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
