c++ - 下面的代码应该为 4 和 0 的输入打印 120.000000。但它只显示 120。为什么?以及如何获得所需的输出?

标签 c++ floating-point

#include <iostream>
using namespace std;

int main()
{
    float deg;
    int h,m;
    cin>>h>>m;     
    deg=h*30 - m*6; 
    cout<<deg;
    return 0;
}

h 和 m 是小时和分钟

问题以度为单位找出时针和分针之间的角度。

最佳答案

cout<< 固定;是答案

#include <iostream>
using namespace std;
int main()
{
 float deg;
 int h,m;
 cin>>h>>m;     
 deg=h*30 - m*6;
 cout<<fixed;
 cout<<deg;
 return 0;
}

关于c++ - 下面的代码应该为 4 和 0 的输入打印 120.000000。但它只显示 120。为什么?以及如何获得所需的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25919414/

相关文章:

ios - stringWithFormat float 的奇怪行为

c++ - boost :rpm 的 typedef

php - PHP 实际上使用 IEEE-754 float 吗?

c++ - Mac错误: Undefined symbols for architecture x86_64

c++ - 如何以干净的方式初始化这个数组?

c++ - 无法从 MSVCRT strtod/sscanf/atof 函数中获取 NaN

javascript - 使用正则表达式从 float 中过滤掉小数

c# - 有没有办法准确地格式化 C# double?

c++ - 即使重载函数的参数计数不匹配,编译器是否应该实例化所有参数依赖类型

c++ - 如何处理回调注册