Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculation gone sideways... 1

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
518
US
Hi All;

I've created a form that will calculate entered values and convert it over to another value. For instance work hours to the number of days.

The code I am using to convert work hours to days (24 work hours in the day). The code calculates fine for any number greater than 2 including fractions, but if the value is either 1 or 2, the return is screwed up.

1 = 4.166 (it should be 0.0416)
2 = 8.333 (it should be 0.083)

Where is the multiply by 100 coming from for these two integers?


here is the code snippet.

Code:
' Hours to Days (24 hours = 1 day)


If hour_box2_24 = "" Then

day_box2_24 = ""


ElseIf hour_box2_24 > 0 Then

day_box2_24 = hour_box2_24 / 24


ElseIf hour_box2_24 = 0 Then

day_box2_24 = 0


ElseIf hour_box2_24 < 0 Then

day_box2_24 = "Error"

End If

Thank you for the assist!

Mike
 
When I run this code for the value 1, I get: 4.16666666666667E-02

Note the E-02 on the end. This is scientific notation for 10^-2

Basically, the calculations are correct. The problem is with the display. Try this:

Replace:

Code:
day_box2_24 = hour_box2_24 / 24

With:

Code:
day_box2_24 = [!]Format([/!]hour_box2_24 / 24[!], "0.0000")[/!]

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hey George,

That worked great! I forgot that VB in forms sometimes doesn't format correctly without the coding override.

Thanks!
 
>sometimes doesn't format correctly without the coding override

Erm ... I know it's pedantic, but it's formatting exactly as expected - just not the way you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top