Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default what is wrong with my fun ,thanks

hi,help me please,

what is wrong with my fun ,thanks
--------------------------------------------------------
Function Length024Round(l As Double) As Double
Dim seisuu As Double
Dim hasu As Double
Dim hasu1 As Double
seisuu = Fix(l)
MsgBox seisuu
hasu = l - seisuu
MsgBox hasu
If hasu < 0.24 Or hasu = 0.24 Then
hasu1 = 0
ElseIf hasu 0.24 And hasu < 0.74 Then
hasu1 = 0.5
ElseIf hasu = 0.74 Then
hasu1 = 0.5
ElseIf hasu 0.74 Then
MsgBox "hasu" & hasu
hasu1 = 1
End If
MsgBox hasu1
Length024Round = seisuu + hasu1
End Function '


Sub Length024RoundTest()
Debug.Print Length024Round(0.74)----0.5--ok
Debug.Print Length024Round(2.74))----3.0--why$B!!(Bnot$B!!(B2.5,why 0.740.74
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 419
Default what is wrong with my fun ,thanks

EXCEL NEWS,

First, how is this not working? It works for me.......although I don't know
what the expected results should be. Are there errors? Are the results
wrong? Please provide values, expected results, and the incorrect results
you are recieving.

Second, this code consolidates things a little (notice I commented out your
code and replaced it with less code that will accomplish the same thing):

Function Length024Round(l As Double) As Double
Dim seisuu As Double
Dim hasu As Double
Dim hasu1 As Double
seisuu = Fix(l)
MsgBox seisuu
hasu = l - seisuu
MsgBox hasu
'If hasu < 0.24 Or hasu = 0.24 Then
If hasu <= 0.24 Then
hasu1 = 0
'ElseIf hasu 0.24 And hasu < 0.74 Then
ElseIf hasu 0.24 And hasu <= 0.74 Then
hasu1 = 0.5
'ElseIf hasu = 0.74 Then
'hasu1 = 0.5
ElseIf hasu 0.74 Then
MsgBox "hasu" & hasu
hasu1 = 1
End If
MsgBox hasu1
Length024Round = seisuu + hasu1
End Function



HTH,

Conan










"EXCEL$B!!(BNEWS" wrote in message
...
hi,help me please,

what is wrong with my fun ,thanks
--------------------------------------------------------
Function Length024Round(l As Double) As Double
Dim seisuu As Double
Dim hasu As Double
Dim hasu1 As Double
seisuu = Fix(l)
MsgBox seisuu
hasu = l - seisuu
MsgBox hasu
If hasu < 0.24 Or hasu = 0.24 Then
hasu1 = 0
ElseIf hasu 0.24 And hasu < 0.74 Then
hasu1 = 0.5
ElseIf hasu = 0.74 Then
hasu1 = 0.5
ElseIf hasu 0.74 Then
MsgBox "hasu" & hasu
hasu1 = 1
End If
MsgBox hasu1
Length024Round = seisuu + hasu1
End Function '


Sub Length024RoundTest()
Debug.Print Length024Round(0.74)----0.5--ok
Debug.Print Length024Round(2.74))----3.0--why$B!!(Bnot$B!!(B2.5,why 0.740.74
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default what is wrong with my fun ,thanks

On Jan 29, 5:27 pm, EXCEL$B!!(BNEWS wrote:
Sub Length024RoundTest()
Debug.Print Length024Round(0.74) ----0.5--ok
Debug.Print Length024Round(2.74))----3.0--why$B!!(Bnot$B!!(B2.5,why 0.740.74
End Sub


Because of the vagaries of binary computer representation.
Specifically, 0.74 is represented by exactly
0.739999999999999991118215802998747676610946655273 4375, where the
fractional part of 2.74 ("hasu") is represented by exactly
0.740000000000000213162820728030055761337280273437 5.

You might be happier with the following logic (although I would
replace MsgBox with Debug.Print):

If Round(hasu,2) <= 0.24 Then
hasu1 = 0
ElseIf Round(hasu,2) <= 0.74 Then
hasu1 = 0.5
Else
MsgBox "hasu " & hasu
hasu1 = 1
End If

Note: For the future, be sure to cut-and-paste. There is an obvious
compilation error in what you posted above.

HTH.


----- original posting -----

On Jan 29, 5:27 pm, EXCEL$B!!(BNEWS wrote:
hi,help me please,

what is wrong with my fun ,thanks
--------------------------------------------------------
Function Length024Round(l As Double) As Double
Dim seisuu As Double
Dim hasu As Double
Dim hasu1 As Double
seisuu = Fix(l)
MsgBox seisuu
hasu = l - seisuu
MsgBox hasu
If hasu < 0.24 Or hasu = 0.24 Then
hasu1 = 0
ElseIf hasu 0.24 And hasu < 0.74 Then
hasu1 = 0.5
ElseIf hasu = 0.74 Then
hasu1 = 0.5
ElseIf hasu 0.74 Then
MsgBox "hasu" & hasu
hasu1 = 1
End If
MsgBox hasu1
Length024Round = seisuu + hasu1
End Function '

Sub Length024RoundTest()
Debug.Print Length024Round(0.74)----0.5--ok
Debug.Print Length024Round(2.74))----3.0--why$B!!(Bnot$B!!(B2.5,why 0.740.74
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
What could be wrong? Don Guillett Excel Programming 0 December 22nd 06 04:36 PM
What am I doing wrong, here? Jim May Excel Programming 3 February 17th 06 11:23 AM
What am I doing wrong? Patrick Simonds Excel Programming 6 December 25th 05 02:24 AM
What am I doing wrong? John Petty Excel Programming 4 October 15th 03 06:43 PM


All times are GMT +1. The time now is 11:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"