当前位置:网站首页>【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保存小数点后两位
边栏推荐
- Is there any good website or software for learning programming? [introduction to programming]?
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Application and principle of ThreadPoolExecutor thread pool
- 工业导电滑环的应用
- Web Security (x) what is OAuth 2.0?
- QT waiting box production
- Leetcode top 100 question 2 Add two numbers
- Rainbow combines neuvector to practice container safety management
- Floweable source code annotation (40) class delegation
猜你喜欢
第05天-文件操作函数
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
基于TI DRV8424驱动步进电机实现调速和行程控制
Using nocalhost to develop microservice application on rainbow
Use and principle of AQS related implementation classes
Tar command
Practice of combining rook CEPH and rainbow, a cloud native storage solution
Leetcode top 100 question 2 Add two numbers
Use and principle of reentrantlock
随机推荐
Mongodb learning chapter: introduction after installation lesson 1
Vérification simple de la lecture et de l'écriture de qdatastream
[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array
使用 Nocalhost 开发 Rainbond 上的微服务应用
Mongodb學習篇:安裝後的入門第一課
Unity drags and modifies scene camera parameters under the editor
Rust hello-word
Ebpf cilium practice (2) - underlying network observability
Web Security (x) what is OAuth 2.0?
el-form表单新增表单项动态校验;el-form校验动态表单v-if不生效;
Intelligent operation and maintenance: visual management system based on BIM Technology
Global and Chinese market of search engine optimization (SEO) software 2022-2028: Research Report on technology, participants, trends, market size and share
More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv. so‘.
el-cascader回显失败;el-cascader回显不出来
[RootersCTF2019]babyWeb
Daily code 300 lines learning notes day 11
複制寶貝提示材質不能為空,如何解决?
Go learning notes (5) basic types and declarations (4)
JDBC常见面试题
Web Security (IX) what is JWT?