0

i'm doing a website to display products and prices and i encounter some error in calculation.

Screenshot of the DataList

<asp:Button ID="SellPrice1" 
          Visible="true" 
          BackColor="#9933FF" 
          Width="200px" 
          BorderStyle="solid" 
          BorderColor="#ffffff" 
          BorderWidth="0px"   
          ForeColor="white" 
          Font-Underline="false" 
          runat="server" 
          CommandArgument='<%# Eval("Barcode")%>' 
          CommandName="Add" 
          Text='<%# "Normal price: RM" + String.Format("{0:0.00}", Convert.ToInt32(Eval("SellPrice_1")) * 1.06, "{0:0.00}") %>' 
          Font-Size="12px" 
          Font-Bold="true"></asp:Button>

          <asp:Button ID="SellPrice2"
          Visible="true"
          BackColor="#9933FF"
          Width="200px"
          BorderStyle="solid"
          BorderColor="#ffffff"
          BorderWidth="0px"
          ForeColor="white" 
          Font-Underline="false"
          runat="server" 
          CommandArgument='<%# Eval("Barcode")%>'
          CommandName="Add" 
          Text='<%#  "Member price: RM" + Eval("SellPrice_2", "{0:0.00}") %>' 
          Font-Size="12px" 
          Font-Bold="true"></asp:Button>

Price of the first item: HEINZ SALAD CREAM ORIGINAL 285G (8.0189)

above is my source code to call 2 prices as show (Normal price, Member price) both data having the same amount currently.

As you guys can see, my normal price included tax which is the number 1.06. The code is working fine but when i count the actual amount by using a calculator, all calculations are wrong excluding the second which is 275.00 as the picture i attached shown.

so my question is, how can i make sure all the calculation can be correct? if my information is not clear enough please let me know.

I found out that my problem is actually the calculation round off all the decimal places only it calculate the amount. but how can i fix this?

TheButterfly
  • 85
  • 1
  • 3
  • 20

1 Answers1

3

Sorry for the trouble, i found the solution and i would post it for future reference.

as here discuss, he is forcing the number to be decimal and as an example, i did that to the number 1.06 as well and the final result is this

Text='<%# "Normal price: RM" + String.Format("{0:0.00}", Convert.ToDecimal(Eval("SellPrice_1")) * 1.06m) %>' 

as you notice, i first Convert.ToDecimal in order to calculate include the decimal places. then i get the error

Operator '*' cannot be applied to operands of type 'decimal' and 'double'

and this is where i force the number

1.06 become 1.06m

in the end i get my final result.

once again sorry for trouble and thanks ИвоНедев for your time

Community
  • 1
  • 1
TheButterfly
  • 85
  • 1
  • 3
  • 20