Round Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dorandoran
    New Member
    • Feb 2007
    • 145

    Round Function

    I am trying to import two functions from MS-ACCESS to sql server 2000. Can anything shed some lights please......... ............

    create Function CalculateSplit( ByVal idMinutes As Double, ByVal ilCount As Double) As Double
    Dim ldMod As Double
    Dim ldMinSplit As Double
    Dim ldDecSplit As Double
    --Debug.Print ldMod
    ldMinSplit = idMinutes / ilCount
    ldMod = ldMinSplit Mod 15
    ldDecSplit = (ldMinSplit - Int(ldMinSplit) )
    If (ldDecSplit <= 0.5) Then
    ldMod = ldMod + ldDecSplit
    Else
    ldMod = ldMod - 1 + ldDecSplit
    End If

    --CalculateSplit = Round(((idMinut es / ilCount) + IIf(((idMinutes / ilCount) Mod 15) = 0, 0, (15 - ldMod))) / 60, 2)
    CalculateSplit = RoundUp(idMinut es / ilCount, 30)

    End Function

    CREATE Function RoundUp(ByVal idMinutes As Double, ByVal id As Double) As Double

    Dim ldMod As Double
    Dim ldMinSplit As Double
    Dim ldDecSplit As Double
    --Debug.Print ldMod

    ldMod = idMinutes Mod id
    ldDecSplit = (idMinutes - Int(idMinutes))
    If (ldDecSplit <= 0.5) Then
    ldMod = ldMod + ldDecSplit
    Else
    ldMod = ldMod - 1 + ldDecSplit
    End If

    RoundUp = Round(((idMinut es) + IIf(((idMinutes ) Mod id) = 0, 0, (id - ldMod))) / 60, 2)

    End Function
  • dorandoran
    New Member
    • Feb 2007
    • 145

    #2
    I hardly get any response from bytes's forums. Are these forums active? I mean are there real developers subscribe to this site? hmm...

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      The forum will not send you email if someone replied to you. You have to come back to check your posts.

      About your question, have you tried the ROUND() built-in function of MS-SQL?

      -- CK

      Comment

      • dorandoran
        New Member
        • Feb 2007
        • 145

        #4
        alter Function oa.CalculateSpl it(@idMinutes Float, @ilCount Float) RETURNS Float
        AS
        BEGIN
        DECLARE @ldMod Float,@ldMinSpl it Float,@ldDecSpl it Float

        SET @ldMinSplit = @idMinutes / @ilCount
        SET @ldMod = cast(@ldMinSpli t as int)% 15
        SET @ldDecSplit = @ldMinSplit - CAST(@ldMinSpli t AS int)

        SET @ldMod =CASE WHEN @ldDecSplit <= 0.5 THEN @ldMod + @ldDecSplit
        ELSE @ldMod - 1 + @ldDecSplit
        END
        RETURN Round(@idMinute s / @ilCount, 60)
        END

        This is not replacing my original roundup and calculatesplit function. please suggest.

        Comment

        • dorandoran
          New Member
          • Feb 2007
          • 145

          #5
          This is the working code. THIS FORUM IS NO GOOD. HARDLY ANY HELP IS RECEIVED.

          alter Function oa.CalculateSpl it(@idMinutes Float, @idCount Float) RETURNS Float
          AS
          BEGIN

          RETURN oa.Roundup(@idm inutes/@idcount)

          END

          alter Function oa.RoundUp(@idM inutes As float) returns float
          as
          begin
          declare @hours as float
          set @hours = CAST(@idminutes AS INT)

          IF @idminutes-@hours > 0
          if @idminutes-@hours > .5
          set @hours = @hours+1
          ELSE
          SET @HOURS=@HOURS+. 5
          return @HOURS
          End

          Comment

          Working...