Reputation: 293
I have the following input
<input type="number" @bind="@object.AllocationPercentage" />
the binding is fine but it is showing a lot of digits
How can I set a specific number format like "F2" or "C2" ?
I know that it is possible for dates
using @bind-format
Upvotes: 7
Views: 17712
Reputation: 293
I could found a solution returning a specific format in the property of the object.
In this way, I could remove the 0 decimals at the end.
private MyClass _object;
public MyClass object
{
get => _object;
set
{
_object = value;
_object. AllocationPercentage = _object.AllocationPercentage / 1.000000000000000000000000000000000m;
}
}
Upvotes: 0
Reputation: 267
Work around could be:
<input type="number" value="@(numberVariable.ToString("G29"))" @onchange="@(e => numberVariable = decimal.Parse(e.Value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture))" />
@code{
private decimal numberVariable {get;set;}
}
Basically you set value without binding and update it during onchange event.
Upvotes: 11
Reputation: 177
At this time it is not possible with native Blazor controls. However, it is available in a number of third party libraries. This is a free one: Radzen
It is also available in premium ones, such as Telerik and Syncfusion.
Upvotes: 0