question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: NumberBox enhancement for the decimal type

See original GitHub issue

Proposal

NumberBox enhancement for the decimal type

Summary

The NumberBox is based on the double type. It should be as easy to use the decimal type instead.

Rationale

Many applications use the decimal instead of the double. If a property of type decimal is used with compiled binding, a casting exception is thrown. With reflection-based binding, the value is always 0.

  • Decimals are often used with properties, and are needed to bind to UI elements, e.g. for money

Scope

Capability Priority
This proposal will allow developers to bind the NumberBox to a decimal type Must

Open Questions

Because a decimal is not part of the Windows Runtime base data types there might not be that many options for this functionality. I was successfully in creating and using a converter to convert from decimal to double - however, this workaround shouldn’t be needed. Probably there’s a way for a built-in conversion, or other options?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
robloocommented, May 18, 2020

I asked for the same when we were first discussing the spec for the NumberBox

A double value is NOT ideal for this. The number of decimal places is important and instead the control ideally would be backed by a Decimal type. I would suggest changing the spec for Value from double to decimal to support this type of use case. https://github.com/microsoft/microsoft-ui-xaml/issues/483#issuecomment-497545781

This is important for currency and other monetary information. However, you are correct that this isn’t possible because decimal is not in WinRT. (using type conversion like you suggested between double and decimal would be useless, the precision is already lost)

@robloo, about that final comment, there is no Decimal type in WinRT. https://github.com/microsoft/microsoft-ui-xaml/issues/483#issuecomment-497564896

There are several sacrifices made in WinRT so it is compatible with the most languages/frameworks. I see this as one of them. If WinRT ever does get decimal support I would love to switch NumberBox to it. However, that would now be a breaking change that Microsoft likely wouldn’t support. So I think this should be closed:

  1. WinRT doesn’t support decimal
  2. Even if decimal type support was added to WinRT, using it in NumberBox would be a breaking change that is likely unjustifiable.

The ship has already sailed I’m afraid.

0reactions
robloocommented, May 19, 2020

@christiannagel

using type conversion like you suggested between double and decimal would be useless, the precision is already lost

That’s an important point. In several scenarios I’m using this wouldn’t be an issue - however this again would limit the usability, and there should be a different option.

If precision isn’t an issue, I don’t think you need decimal. Just use Convert to go between double/decimal as you desire (assuming .net). Converting values is quite easy and I don’t think limits usability of NumberBox at all. In fact I could argue the opposite and say double is far more commonplace than decimal and switching to decimal hinders ease of use.

@mdtauk

My suggestion was that the Value type would change, based on the ValueType chosen. So it could be a double by default, but if the control was set to a ValueType of Decimal, then that would be the type used by the Value property.

That isn’t possible without changing to dynamic or object as the backing type for Value. This violates all sorts of API design principles. @christiannagel is correct and we would need another property of type decimal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NumberBox - Fix Numeric and decimal length
Hi Sirs, Please let me know if there is options to fix the length of digits in dx number box. I want to...
Read more >
DECIMAL type | Databricks on AWS
Represents numbers with a specified maximum precision and fixed scale. In this article: Syntax; Limits; Literals; Examples; Related. Syntax.
Read more >
Blazor Numeric Textbox Overview - Documentation - Telerik
The Blazor Numeric Textbox component allows the user to enter decimal values and no text. The developer can control minimum, maximum values, steps...
Read more >
Proposal to Add Decimal Floating Point Support to C++ ...
Unfortunately, decimal values cannot, in general, be represented accurately using binary floating points even when the decimal values only uses a few digits....
Read more >
DECIMAL
The DECIMAL data type stores exact, fixed-point numbers. This type is used when it is important to preserve exact precision, for example, with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found