Krishnan Suba

Krishnan Suba

  • 1.8k
  • 46
  • 2.2k

How to remove trailing zeros in a decimal in C#

Dec 9 2019 5:32 AM
I using the code for price column
C# code:
sku.SKUPrice = ValidationHelper.GetDecimal(txtActualPrice.Text, default(decimal));
The value is binding the textbox is "0.000000000"
I need the output is "0.00" only.
The database column datatype is "decimal(18.9)"
If I run the "
alter table COM_SKU alter Column SKUPrice decimal(18,2) not null" query I am getting below error message.
Msg 5074, Level 16, State 1, Line 5
The index 'IX_COM_SKU_SKUPrice' is dependent on column 'SKUPrice'.
Msg 4922, Level 16, State 9, Line 5
ALTER TABLE ALTER COLUMN SKUPrice failed because one or more objects access this column.
<cms:CMSTextBox ID="txtActualPrice" runat="server" EnableViewState="false" CssClass="input__text"></cms:CMSTextBox>
<asp:RequiredFieldValidator ID="rfvActualPrice" runat="server" CssClass="EditingFormErrorLabel" ControlToValidate="txtActualPrice"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revActualPrice" runat="server" CssClass="EditingFormErrorLabel"
ControlToValidate="txtActualPrice" ValidationExpression="((\d+)((\.\d{1,100})?))$"></asp:RegularExpressionValidator>

Answers (2)