I have one issue.Any help would be great.
I have a webnumericedit control (Infragistics 2008) which needs to hold both 2 decimal point and 3 decimal point values.
I have tried setting MinDecimalPlaces="Three" and round the value to 2 or 3 decimal places as I want depending on some conditions.
The problem is even when I want only 2 decimal places to be displayed, it suffixes a '0' at the end and displays.
Eg:
When I want only 3 decimal places
I am rounding 1234.41222 to 1234.412, it is displayed as 1234.412
When I want only 2 decimal places
I am rounding 1234.41222 to 1234.41 , but it is displayed as 1234.410
How can I get it displayed as 1234.41 in the second case, while retaining the first case as it is.
I have tried many permutations, but they dont find effect.
Hi yi,
The number of decimal places (or maximum decimal places) is defined by culture. To change that setting, you need to use NumberFormat property. Below is example (within Page.OnLoad or similar):
System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CreateSpecificCulture("en-EN");ci.NumberFormat.NumberDecimalDigits = 3;this.WebNumericEdit1.NumberFormat = ci.NumberFormat;
To reduce number of decimal places on client, you may process client events and adjust value according to your requirement. For example, you may process ValueChange and do something like
<script type="text/javascript">function valueChangeEvt(editor, val, evt){ var twoDecimals = document.getElementById('Checkbox1').checked; if(twoDecimals) editor.setValue(Math.round(val * 100) / 100);}</script><igtxt:WebNumericEdit ID="WebNumericEdit1" runat="server"> <ClientSideEvents ValueChange="valueChangeEvt" /></igtxt:WebNumericEdit><input id="Checkbox1" type="checkbox" />
On client decimal places are strored in member variable "decimals". So, you may play with that too. For example, you may process blur event and try to change value of that variable (no support in case of misbehavior). Below is example:
<script type="text/javascript">function blurEvt(editor, val, evt){ var twoDecimals = document.getElementById('Checkbox1').checked; editor.decimals = twoDecimals ? 2 : 3;}</script><igtxt:WebNumericEdit ID="WebNumericEdit1" runat="server"> <ClientSideEvents Blur="blurEvt" /></igtxt:WebNumericEdit><input id="Checkbox1" type="checkbox" />