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

RadNumericTextBox: Remove "Unused" Decimals

2 Answers 178 Views
Input
This is a migrated thread and some comments may be shown as answers.
kencox
Top achievements
Rank 1
kencox asked on 06 Jan 2010, 12:44 AM
Okay, this is a strange one, but the boss is asking for it....

He doesn't want to display decimals in a RadNumericTextBox if the decimal portion equals .00.

For example, if the value is 123.44, the texbox should display

123.44

However, if the number is 123.00 then the textbox should display

123

Does that make any sense? Does anyone have any idea how this could be done without a TON of "if" coding?

Ken

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 06 Jan 2010, 09:37 AM
Hello Ken,

You can achieve the described behavior by setting  NumberFormat.AllowRounding  to "false". If you don't want to disable rounding, then you will have to use some custom Javascript. Subscribe to the ValueChanged and Blur client events. In the event handler, you can access the formatted value inside the textbox with sender._textBoxElement.value.

<telerik:RadNumericTextBox ID="RNTB1" runat="server">
    <ClientEvents OnBlur="RemoveZeros" OnValueChanged="RemoveZeros" />
</telerik:RadNumericTextBox>
 
<script type="text/javascript">
 
function RemoveZeros(sender, args)
{
    var tbValue = sender._textBoxElement.value;
    if (tbValue.indexOf(".00") != -1)
        sender._textBoxElement.value = tbValue.substr(0, tbValue.indexOf(".00"));
}
 
</script>



Greetings,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
kencox
Top achievements
Rank 1
answered on 06 Jan 2010, 06:43 PM
Perfect! Thanks Dimo!

Ken
Tags
Input
Asked by
kencox
Top achievements
Rank 1
Answers by
Dimo
Telerik team
kencox
Top achievements
Rank 1
Share this question
or