[CLOSED] Numberfield strips trailing zeros

  1. #1

    [CLOSED] Numberfield strips trailing zeros

    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
    Last edited by Daniil; Jan 31, 2013 at 3:43 AM. Reason: [CLOSED]
  2. #2
    Try this
    TrimTrailedZeros="false"
  3. #3
    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
  4. #4
    Quote Originally Posted by RCM View Post
    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.prototype.setValue, function (v) {
    	if (this.trimTrailedZeros === false && this.getRawValue().lastIndexOf(this.decimalSeparator) > -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));
    	}
    });
  5. #5
    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.
  6. #6
    Quote Originally Posted by RCM View Post
    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.decimalPrecision = 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.
  7. #7
    That did not work. I tried that even before opening this thread
  8. #8
    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}.decimalPrecision = #{Precision}.getValue();
                    #{txtNewSingleParameterNumericField}.setValue(#{txtNewSingleParameterNumericField}.getRawValue());
                ">
                </Click>
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>

Similar Threads

  1. NumberField's Value Bug?
    By zxd9915 in forum 1.x Help
    Replies: 4
    Last Post: Mar 20, 2012, 5:44 AM
  2. [CLOSED] Multiple Tab Strips in line, with Container
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 31, 2011, 9:03 AM
  3. Replies: 3
    Last Post: Mar 10, 2011, 2:05 PM
  4. [CLOSED] NumberField rounding the Zeros(Coolite Version 0.8)
    By yobnet in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 01, 2010, 2:02 AM
  5. 0 in numberfield
    By [WP]joju in forum 1.x Help
    Replies: 1
    Last Post: Sep 22, 2009, 10:19 AM

Posting Permissions