为什么自动推断此变量为double而不是float?

编程入门 行业动态 更新时间:2024-10-07 10:19:38
本文介绍了为什么自动推断此变量为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?

本文发布于:2023-11-29 15:41:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:推断   量为   而不是   double   float

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!