| |

VerySource

 Forgot password?
 Register
Search
View: 814|Reply: 5

Why is the output value incorrect from the predetermined value? Please come in.

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-4 22:00:01
| Show all posts |Read mode
long a = 116;
long b = 20;
long c = 43;
long d = (a + (double) b / 60 + (double) c / 3600) * 100000;
cout << "d =" << d << endl;

Why is the output d = 11634527?
Rounding by calculator should be 11634528.

Can anyone tell me what the problem is? How to solve it?
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-4 23:39:01
| Show all posts
Not rounded when processed by a computer
It converts decimals to integers.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-5 10:33:01
| Show all posts
Is there any way to get the correct value?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-5 10:57:01
| Show all posts
Use rounding functions, or do it yourself
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-1-8 22:00:01
| Show all posts
Add 0.5 before rounding
Reply

Use magic Report

0

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-3 18:15:01
| Show all posts
Is there any way to get the correct value?
-------------------------------------

What is the correct value? Is the rounded result the correct value? Analyze specific issues!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list