Skip to content

Commit 0da58fb

Browse files
KB Botdimodi
authored andcommitted
Added new kb article numeric-textbox-kb-zero-decimals
1 parent 9579125 commit 0da58fb

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: How to Display Currency Format Without Decimals
3+
description: Learn how to display a currency value without decimal places in a Blazor NumericTextBox by adjusting the Format and Decimals parameters.
4+
type: how-to
5+
page_title: How to Display Currency Format Without Decimals
6+
slug: numeric-textbox-kb-zero-decimals
7+
tags: numeric-textbox, blazor, format, decimals, currency
8+
res_type: kb
9+
ticketid: 1661907
10+
---
11+
12+
## Environment
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>NumericTextBox for Blazor</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
## Description
23+
24+
When using the [NumericTextBox](https://docs.telerik.com/blazor-ui/components/numerictextbox/overview) with a currency format, setting the `Decimals` parameter to 0 does not prevent decimal places from being displayed. This occurs because the `Format="C"` parameter, which specifies currency formatting, overrides the `Decimals` parameter by adding two decimal places by default, according to the local currency settings (e.g., £).
25+
26+
This KB article also answers the following questions:
27+
- How to display currency values without decimals in a NumericTextBox?
28+
- How to use the Format parameter to control decimal places in NumericTextBox?
29+
- What is the effect of the Decimals parameter in NumericTextBox when using currency format?
30+
31+
## Solution
32+
33+
To display a currency value without decimal places in the NumericTextBox while using the currency format (`C`), set the `Format` parameter to `"C0"`. This explicitly sets the number of decimal places to zero in the formatted currency value.
34+
35+
````CSHTML
36+
37+
<TelerikNumericTextBox @bind-Value="@BoundAmountTo" Decimals="0" Format="C0" Step="1m" />
38+
39+
@code {
40+
private decimal BoundAmountTo { get; set; } = 20.00m;
41+
}
42+
43+
````
44+
45+
It is crucial to understand that the `Decimals` parameter only affects the allowed decimal places during typing (when the input is focused). Conversely, the `Format` parameter determines how the value is displayed when the input is not focused, including the number of decimal places shown in the formatted output.
46+
47+
## See Also
48+
49+
- [NumericTextBox Overview](https://docs.telerik.com/blazor-ui/components/numerictextbox/overview)
50+
- [NumericTextBox Parameters](https://docs.telerik.com/blazor-ui/components/numerictextbox/overview#numeric-textbox-parameters)
51+
- [Standard Numeric Format Strings - Currency Format Specifier (C)](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#currency-format-specifier-c)

0 commit comments

Comments
 (0)