当前位置:网站首页>【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保存小数点后两位
边栏推荐
- Like cloud functions
- Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
- Unity项目心得总结
- Use and principle of AQS related implementation classes
- Rust hello-word
- Using nocalhost to develop microservice application on rainbow
- Some common commands of podman
- Cockroachdb: the resistant geo distributed SQL database paper reading notes
- Daily question -leetcode1175- permutation of prime numbers - Mathematics
- Go learning notes (5) basic types and declarations (4)
猜你喜欢

Actual combat: basic use of Redux

Use and principle of wait notify

智慧运维:基于 BIM 技术的可视化管理系统

Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications

Causes of short circuit of conductive slip ring and Countermeasures

工业导电滑环的应用

How to meet the requirements of source code confidentiality and source code security management

0xc000007b the application cannot start the solution normally (the pro test is valid)

How to traverse massive data in redis

数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
随机推荐
Floweable source code annotation (40) class delegation
LevelDB源码分析之LRU Cache
Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
担心侵权?必备无版权素材网站分享,不用担心视频剪辑缺素材
Use and principle of wait notify
Global and Chinese market of digital badge 2022-2028: Research Report on technology, participants, trends, market size and share
C# wpf 使用DockPanel实现截屏框
HDU - 1069 Monkey and Banana(DP+LIS)
[RootersCTF2019]babyWeb
Usage and principle of synchronized
One click deployment of highly available emqx clusters in rainbow
Receiving package install and uninstall events
More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv.so‘.
QT等待框制作
Flutter 实现每次进来界面都刷新数据
Day 05 - file operation function
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 gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share
Memtable for leveldb source code analysis
Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share