Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for binding decimal, double, float data type with configurable formatting #5523

Open
Andrzej-W opened this issue May 17, 2018 · 30 comments
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) help candidate Indicates that the issues may be a good fit for community to help with. Requires work from eng. team Pillar: Technical Debt Priority:2 Work that is important, but not critical for the release severity-major This label is used by an internal tool

Comments

@Andrzej-W
Copy link

This should work

<input bind="@price"/>
@functions
{
    decimal price;
}

but currently we get an exception:
Error: System.ArgumentException: 'bind' does not accept values of type System.Decimal. To read and write this value type, wrap it in a property of type string with suitable getters and setters.

Decimal data type is paramount in every business application. We don't want to use "hacks" and convert it to/from string manually every time.

Support for formatting is also crucial (number of decimal places, decimal and thousandth separators)

@floreseken
Copy link

I can confirm this.

@Andrzej-W
Copy link
Author

Andrzej-W commented May 22, 2018

I have just found that @Daddoon is working on this (dotnet/blazor#630) and it is almost ready. Thank you @Daddoon.

@Daddoon
Copy link

Daddoon commented May 22, 2018

Coming back on that in few days (as stated in dotnet/blazor#630 , i was working on some Xamarin/Blazor interop stuff).
I must update the test case project.

@aspnet-hello aspnet-hello transferred this issue from dotnet/blazor Dec 17, 2018
@aspnet-hello aspnet-hello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one area-blazor Includes: Blazor, Razor Components labels Dec 17, 2018
@codeinstinct
Copy link

Is there a work around available for this until the issue gets resolved ?

I have a value 0.00008900 which when I bind to a text box, gets represented as 8.9E-05.
It should be represented as "0.00008900" itself and not the scientific notation.

What is the best way to do this in blazor today?

@Andrzej-W
Copy link
Author

Partially related issue (formatting for numbers): #9435

@chrdlx
Copy link

chrdlx commented Jul 22, 2019

Hi! What is the current recommended way to bind decimal objects?
I've found myself using inputs only with string properties to then cast manually each property to the datatype and format I need. So basically I have 2 classes, one with all strings (for the text inputs), and another with appropriate data types.

Is this how it's supposed to be used?

Thanks & Regards!!

@SteveSandersonMS
Copy link
Member

@rynowak This is fixed now, right? (As of preview 8, I mean)

@rynowak
Copy link
Member

rynowak commented Jul 24, 2019

No, we did not add support for formatting for numeric types. Only dates support formatting.

@SteveSandersonMS
Copy link
Member

Oh, I thought decimal etc would now be bindable due to a built-in typeconverter. I know that doesn't make it have custom formatting though.

@rynowak
Copy link
Member

rynowak commented Jul 25, 2019

We have bespoke support for decimal.

@mkArtakMSFT mkArtakMSFT modified the milestones: 3.1.0, 5.0.0 Aug 12, 2019
@mkArtakMSFT mkArtakMSFT modified the milestones: 5.0.0, 5.0.0-preview1 Aug 19, 2019
@ghost
Copy link

ghost commented Sep 19, 2019

For a one-way binding scenario, what is the equivalent to @Html.DisplayFor(x => x.SomeProperty) where SomeProperty has the DisplayFormat attribute? E.g. I want to format a number to 3 decimal places (and not issue .ToString("N3") in the razor code.

@SteveSandersonMS
Copy link
Member

There's no built-in library support for formatting based on a [DataFormat] attribute. It's technically possible that we or a third party could implement a helper that looks like DisplayWithFormat(() => yourObject.SomeProperty), but it's not something we're currently planning.

@ghost
Copy link

ghost commented Jun 29, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Dec 19, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, .NET 9 Planning Dec 19, 2023
@ghost
Copy link

ghost commented Dec 19, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT mkArtakMSFT added api-suggestion Early API idea and discussion, it is NOT ready for implementation help candidate Indicates that the issues may be a good fit for community to help with. Requires work from eng. team Pillar: Technical Debt Priority:2 Work that is important, but not critical for the release and removed Pillar: Complete Blazor Web api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) help candidate Indicates that the issues may be a good fit for community to help with. Requires work from eng. team Pillar: Technical Debt Priority:2 Work that is important, but not critical for the release severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests