Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

Strange behavior in Excel when counting Work Hours and Work Super Hours.

I composed the next Worksheet in order to count my Workhours.

Work Hours Worksheet Other solutions proposed over the internet would not work, since the Workhours amount per day was not fixed at first. The problem makes its appearrance sometimes when the "Total Work Hours" equal the "Normal Work Hours". When i try to format the Super Hours Cells using conditions, i don't get the correct result. The equality seems not to be the case. Conditional format

Cell K9: Negative or very big date and time values are displayed as pound signs (###)

The following information are important:

  1. The Cells A4:B500, F4, F5 are formated like: Hour 13:30
  2. The Cells J7:R9 are formated like: Custom [h]:mm
  3. J7: =SUM($C4:$C34) and respectively Cells K7,L7...
  4. J8: =J4*$F$5 and respectively Cells K8,L8...
  5. J9: =IF(J$7>=J$8;J$7-J$8;J$8-J$7) and respectively Cells K9,L9...

I would like to know why this happens and if there is a solution or a different approach.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you perform math operations in Excel you will sometimes get floating point errors. They come about because Excel is limited to 15 digit precision so significant digits after 15 are ignored.

Times in Excel are all percentages of days. Computers calculate in binary so all those decimals have to be converted to binary before the math operation and the result has to be converted back to decimal.

For example, something as simple as 0.1 in binary is like Pi in decimal - it isn't a finite number.

Do math on those converted numbers and there are going to be rounding errors.

If you change the format of K9 to General, you will probably find it's a very small negative number expressed in scientific notation.

Rounding the result in K9 to something greater than 4 to allow for 1440 minutes in a day, should get rid of the error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...