This is a migrated thread and some comments may be shown as answers.

Rounded value after 2 decimal digit

2 Answers 184 Views
Input
This is a migrated thread and some comments may be shown as answers.
Olo
Top achievements
Rank 1
Olo asked on 10 Mar 2009, 09:42 AM
Hi,
in radnumerictextbox I set:   <NumberFormat KeepNotRoundedValue="True" /> and decimal digits = 2.
And now when I write: 12,1299 the controls shows 12,13.
I want that digits after 2 decimal digits will remove automatically .
How can I do that?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Mar 2009, 11:59 AM
Hello Olo,

The KeepNotRoundedValue property specifies whether the control will keep its not rounded value (true) and show it when it is focused. Otherwise (false) the old behavior is preserved, where the  actual value of the control is the rounded value. Try the following client side code for turn off the automatic rounding of and setting the decimal values.

JavaScript:
<script type="text/javascript">  
function Changed()   
{   
    var input = $find("<%= RadNumericTextBox1.ClientID %>");  
    var number = input.GetValue().toString();   
    if(number.length - number.indexOf('.') > 2 && number.indexOf('.') > 0)   
    {   
        number = number.substring(0, number.indexOf('.') + input._numberFormat.DecimalDigits + 1);   
        input.SetValue(number);   
    }   
}  
</script> 

ASPX:
<telerik:radnumerictextbox id="RadNumericTextBox1"   runat="server">          
        <NumberFormat DecimalDigits="2" AllowRounding="false" /> 
        <ClientEvents OnValueChanged="Changed" /> 
</telerik:radnumerictextbox> 

Thanks,
Princy.
0
Daniel
Telerik team
answered on 10 Mar 2009, 12:30 PM
Hello Olo,

You can implement such behavior using JS code:
<script language="javascript" type="text/javascript"
    function stripNumbers(sender, args) 
    { 
        var val = String(args.get_newValue()); 
        if (val.length - vale.indexOf('.') > 2) 
            args.set_newValue(val.substr(0, val.indexOf('.') + 3)); 
    } 
</script> 
 
<telerik:RadNumericTextBox ID="ntb" runat="server" ClientEvents-OnValueChanging="stripNumbers"
</telerik:RadNumericTextBox> 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Input
Asked by
Olo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or