PDA

View Full Version : [CLOSED] Numberfield strips trailing zeros



RCM
Jan 23, 2013, 8:51 PM
I have a NumberField defined as shown below.




<ext:NumberField ID="txtNewSingleParameterNumericField" runat="server" TabIndex="54" DecimalPrecision="20"
FieldLabel="Number" AnchorHorizontal="100%"
EnableKeyEvents="true" AllowDecimals="true" AllowNegative="true">
<Listeners>
</Listeners>
</ext:NumberField>


I want to be able to enter the value 13.50 , but when i enter the value, the numberfield trims it to 13.5 how can I make the numberfield to display the trailing zero.

Regards

Vladimir
Jan 23, 2013, 9:28 PM
Try this


TrimTrailedZeros="false"

RCM
Jan 24, 2013, 9:14 PM
the TrimTrailedZeros="false" worked but now the numbers of zeros is equal to the decimal precision. The decimal precision in my situation is dynamically updated but I statically set it to 20 and would like to be able to dynamically set the value based on the user setting .

for instance, when i set the value to 24.00, it changes to 24.00000000000000000000

Baidaly
Jan 25, 2013, 12:07 AM
the TrimTrailedZeros="false" worked but now the numbers of zeros is equal to the decimal precision. The decimal precision in my situation is dynamically updated but I statically set it to 20 and would like to be able to dynamically set the value based on the user setting .

for instance, when i set the value to 24.00, it changes to 24.00000000000000000000

Hello!

If I've understood you correctly try the following code:



Ext.form.NumberField.prototype.setValue = Ext.Function.createSequence(Ext.form.NumberField.p rototype.setValue, function (v) {
if (this.trimTrailedZeros === false && this.getRawValue().lastIndexOf(this.decimalSeparat or) > -1) {
var rawL = this.getRawValue().split(this.decimalSeparator)[1].length,
l = arguments[0].lastIndexOf(this.decimalSeparator) == -1 ? 0 : arguments[0].split(this.decimalSeparator)[1].length,
value = this.getValue();

if (rawL > l)
this.setRawValue(value.toFixed(l).replace(".", this.decimalSeparator));
}
});

RCM
Jan 25, 2013, 4:02 PM
I am talking about updating the decimal precision dynamically. Not the decimal separator. For instance I want to be able to set the decimal precision from 3 decimal places to 4 decimal places. or from 20 decimal places as it is now to 5 decimal places in code.

Baidaly
Jan 25, 2013, 8:24 PM
I am talking about updating the decimal precision dynamically. Not the decimal separator. For instance I want to be able to set the decimal precision from 3 decimal places to 4 decimal places. or from 20 decimal places as it is now to 5 decimal places in code.

Unfortunately, there is no default way to do this you have to change decimalPrecision field and then reassign value:



App.txtNewSingleParameterNumericField.decimalPreci sion = 2;
App.txtNewSingleParameterNumericField.setValue(App .txtNewSingleParameterNumericField.getRawValue());


However, you can add this code as a method to NumberField class or just put it to separate function on your page.

RCM
Jan 26, 2013, 9:16 PM
That did not work. I tried that even before opening this thread

Baidaly
Jan 26, 2013, 9:45 PM
I've tried the following and it works fine:



<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:NumberField ID="txtNewSingleParameterNumericField" runat="server" TabIndex="54"
FieldLabel="Number" AnchorHorizontal="100%"
EnableKeyEvents="true" AllowDecimals="true" AllowNegative="true" TrimTrailedZeros="False">
<Listeners>
</Listeners>
</ext:NumberField>

<ext:NumberField ID="Precision" runat="server" Text="2"
FieldLabel="Precision" AnchorHorizontal="100%"
EnableKeyEvents="true" AllowDecimals="true" AllowNegative="true">
</ext:NumberField>
<ext:Button runat="server" Text="Change Precision">
<Listeners>
<Click Handler="
#{txtNewSingleParameterNumericField}.decimalPrecis ion = #{Precision}.getValue();
#{txtNewSingleParameterNumericField}.setValue(#{tx tNewSingleParameterNumericField}.getRawValue());
">
</Click>
</Listeners>
</ext:Button>
</form>
</body>
</html>