当前位置:网站首页>[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved
[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved
2022-07-01 05:36:00 【There is a long way to go】
【 scene 】
To achieve 10.00 - 5.00 The result is equal to 5.00 Instead of being equal to 5
Because it is an integer just after subtraction , Want to keep two decimal places , You can't keep it directly , Even with double Save the data
【 Method 】
#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;
}
result

【 Add 】
You can also use c Methods , direct %l2f Save two decimal places
边栏推荐
- 基于TI DRV8424驱动步进电机实现调速和行程控制
- How to meet the requirements of source code confidentiality and source code security management
- What things you didn't understand when you were a child and didn't understand until you grew up?
- Qt编译时,出现 first defined here,原因及解决方法
- Common solutions for mobile terminals
- 新手在挖财开通证券账户安全吗?
- Data governance: data governance management (Part V)
- printk 调试总结
- Leetcode top 100 question 2 Add two numbers
- Leetcode top 100 questions 1 Sum of two numbers
猜你喜欢

【医学分割】u2net

Intelligent operation and maintenance: visual management system based on BIM Technology

Actual combat: gateway api-2022.2.13

基于TI DRV8424驱动步进电机实现调速和行程控制

实战:redux的基本使用

Ssm+mysql second-hand trading website (thesis + source code access link)

0xc000007b应用程序无法正常启动解决方案(亲测有效)

Multi table operation - foreign key cascade operation

Spanner 论文小结

Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
随机推荐
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
College community management system based on boot+jsp (with source code download link)
基于微信小程序的青少年生理健康知识小助手(免费获取源码+项目介绍+运行介绍+运行截图+论文)
busybox生成的东西
Txncoordsender of cockroachdb distributed transaction source code analysis
移动端常用解决方案
HDU - 1024 Max Sum Plus Plus(DP)
Qt编译时,出现 first defined here,原因及解决方法
使用 Nocalhost 开发 Rainbond 上的微服务应用
QT waiting box production
Web Security (IX) what is JWT?
Rust基础入门之变量绑定与解构
数据库连接池的简单实现
Web Security (x) what is OAuth 2.0?
Application and principle of ThreadPoolExecutor thread pool
Boot + jsp University Community Management System (with source Download Link)
Mongodb learning chapter: introduction after installation lesson 1
SSM的教务管理系统(免费源码获取)
Rainbow combines neuvector to practice container safety management
Intelligent operation and maintenance: visual management system based on BIM Technology