[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

Sum Of MAXROW, MAXCOL

How can i get the sum of Maxrow, maxcol  that includes up to 6 digits?
example: 4.456780
               5.890900
             --------------
sum       10.347680

my code below will not include the 3 to 5 digits.


Private Function TotalAmount() As Double
Dim PRICE As Double, QTY As Double, Amt As Double
On Error Resume Next
PRICE = 0
    For MAXROW = x.LowerBound(1) To x.UpperBound(1)
        For MAXCOL = x.LowerBound(2) To x.UpperBound(2)
            Select Case MAXCOL
                    Case 7
                        QTY = x(MAXROW, MAXCOL)
                    Case 12
                        Amt = x(MAXROW, MAXCOL)
                       PRICE = PRICE + QTY * Amt
            End Select
        Next MAXCOL
    Next MAXROW
TotalAmount = Format(PRICE, "#,###,##0.00##")
End Functio

Open in new window

0
Whing Dela Cruz
Asked:
Whing Dela Cruz
  • 5
  • 4
1 Solution
 
CWS (haripriya)Commented:
Not sure, what you are asking.
You have the format command on line 16 which is truncating the digits.
>>TotalAmount = Format(PRICE, "#,###,##0.00##")
hope this helps.
0
 
Whing Dela CruzAuthor Commented:
sorry but i could not explain very well,
My problem is that ... the result of the (TotalAmount) will round off up to two digits only.
and when i calculate, using the calculator there is a difference

example  

amt is (15.582291)  *  qty (1)   then the result of my  TotalAmount is only 15.58

i want to get the TotalAmount 15.582291 as this is a original

the result would be 15.582291 not 15.80

0
 
CWS (haripriya)Commented:
Then, remove the format command.
Try this.
Private Function TotalAmount() As Double
Dim PRICE As Double, QTY As Double, Amt As Double
On Error Resume Next
PRICE = 0
    For MAXROW = x.LowerBound(1) To x.UpperBound(1)
        For MAXCOL = x.LowerBound(2) To x.UpperBound(2)
            Select Case MAXCOL
                    Case 7
                        QTY = x(MAXROW, MAXCOL)
                    Case 12
                        Amt = x(MAXROW, MAXCOL)
                       PRICE = PRICE + QTY * Amt
            End Select
        Next MAXCOL
    Next MAXROW
TotalAmount = PRICE
End Function

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Whing Dela CruzAuthor Commented:
Hi! i tried it but still the same.. i add
text1.text  = Format(Price, "#,###,##0.0000")   because i want the result to display in text1.text
but the display is 15.5800 instead of 15.582291

I  want to display the entire number of 15.582291 in the textbox...

My qty is 1 and my amt is 15.582291
I hope you can understand my example. Thanks...!!

0
 
CWS (haripriya)Commented:
Insead of this
>>text1.text  = Format(Price, "#,###,##0.0000")

Give this,

text1.text  = Price
0
 
Whing Dela CruzAuthor Commented:
Hi!,
I did it and the result is still  15.58
My problem is to get the sum total of case 12
under the row, the result is displayed as 15.582291 but  when i execute to display to textbox the result would be 15.58

Do i need to re-construct my questions? because i do believed that my question is not understandable because i myself got difficulties  on how to deliver this question very well.
but i'm willing to re-construct it. Thanks!!!
0
 
CWS (haripriya)Commented:
Whereever you have given the Format(), remove that and see.

Also, check the runtime values in the debugger to see where exactly the value is getting round off.

Let me know if you need further help.
0
 
Whing Dela CruzAuthor Commented:
I tried to remove the all (Format()) and finally i found out the problems..
I really thank you   cyberwebservice, now i can to continue my project...
thanks so much!! More power to you...
0
 
CWS (haripriya)Commented:
Thanks for the accepted answer.
Always happy to help :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now