当前位置:网站首页>【QT】qt加减乘除之后,保留小数点后两位
【QT】qt加减乘除之后,保留小数点后两位
2022-07-01 05:25:00 【路漫漫其远,吾求索】
【场景】
要实现10.00 - 5.00的结果等于5.00而不是等于5
因为正好减完之后是个整数,想要保留小数点后两位,直接保留是不行,即使是用double存数据
【方法】
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
double a = 10.00;
double b = 5.00;
double c = (a-b);
cout << setiosflags(ios::fixed) << setprecision(2) << c << endl;
}
MainWindow::~MainWindow()
{
delete ui;
}
结果

【补充】
也可以使用c的方法,直接%l2f保存小数点后两位
边栏推荐
- Variable binding and deconstruction for rudimentary rust
- eBPF Cilium实战(2) - 底层网络可观测性
- Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
- Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation
- Redis数据库的部署及常用命令
- 工业导电滑环的应用
- 複制寶貝提示材質不能為空,如何解决?
- Copy baby prompt: material cannot be empty. How to solve it?
- Using nocalhost to develop microservice application on rainbow
- 智慧运维:基于 BIM 技术的可视化管理系统
猜你喜欢

Summary of spanner's paper

CockroachDB: The Resilient Geo-Distributed SQL Database 论文阅读笔记

如何创建一个根据进度改变颜色的进度条

Design and application of immutable classes

el-cascader回显失败;el-cascader回显不出来

Leetcode top 100 questions 1 Sum of two numbers

C# wpf 使用DockPanel实现截屏框

Daily code 300 lines learning notes day 11

CockroachDB 分布式事务源码分析之 TxnCoordSender

Unity项目心得总结
随机推荐
使用 Nocalhost 开发 Rainbond 上的微服务应用
工业导电滑环的应用
0xc000007b the application cannot start the solution normally (the pro test is valid)
Day 05 - file operation function
[Yugong series] February 2022 Net architecture class 005 ABP vNext Net core web application getting started configuration
[ffmpeg] [reprint] image mosaic: picture in picture with wheat
Explanation of characteristics of hydraulic slip ring
Rust基础入门之变量绑定与解构
Unity 使用Sqlite
Use and principle of reentrantlock
液压滑环的特点讲解
busybox生成的东西
el-form表单新增表单项动态校验;el-form校验动态表单v-if不生效;
How to start learning editing? Detailed analysis of zero basis
Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
Some common commands of podman
One click deployment of highly available emqx clusters in rainbow