为什么自动推断此变量为double而不是float? [英] Why does auto deduce this variable as double and not float?

查看:74
本文介绍了为什么自动推断此变量为double而不是float?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码片段中, auto 将变量推导出为 double ,但是我想要 float .

In the snippet below, auto deduces the variable to double, but I want float.

auto one = 3.5;

对于带小数点的文字,是否始终使用 double ?如何确定浮点数和双精度数?

Does it always use double for literals with a decimal point? How does it decide between float and double?

推荐答案

文字 3.5 的类型为 double .对于 float ,请使用 3.5f

Type of literal 3.5 is double. For float please use 3.5f

您可以使用此代码段来查看各种类型的信息.

You can play with this snippet to see various type information.

这篇关于为什么自动推断此变量为double而不是float?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆