| |

VerySource

 Forgot password?
 Register
Search
View: 925|Reply: 6

My brother uses a variable of type INT. When this variable reaches a preset value, 80% of this variable is taken.

[Copy link]

4

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-24 00:00:01
| Show all posts |Read mode
I use a variable of type INT. When this variable reaches a preset value, 80% of this variable is taken. My approach is int = int * 0.8. Why ca n’t I convert implicitly?
Reply

Use magic Report

0

Threads

46

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-2-8 20:00:02
| Show all posts
i = (int) i * 0.8
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-11 19:00:01
| Show all posts
Is such that
i = (int) (i * 0.8);
or
i = Convert.ToInt32 (i * 0.8);
Reply

Use magic Report

0

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-18 23:30:02
| Show all posts
i = i * 4/5;

It seems that there is no need to switch, and the efficiency is much better.
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-4-19 09:15:01
| Show all posts
Just use the double type
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-4-19 10:30:02
| Show all posts
double d = i * 0.8
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-1 20:30:01
| Show all posts
0.8 is a double type... it seems that this is implicitly inconvertible
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