Current filter:
                                You should refresh the page.
                                  • Hi,

                                    When dxNumberBox has negative values that round to 0, they are displayed as -0.

                                    Is this expected behaviour?

                                    See Sample
                                • Marion (DevExpress Support) 04.26.2018

                                  Hello Sebastian,

                                  Thank you for pointing out this issue to us. I have reproduced it with your online example and passed this ticket to our developers for further research.

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Sebastian,

                                We have examined this behavior and decided that it is correct. In fact, JavaScript has a negative zero, which is not equal to zero:

                                Are +0 and -0 the same?

                                The standard Math.round(-0.1) method returns -0, not 0. Since NumberBox does not change a value, but just formats it, it shows a real -0 value. If NumberBox showed 0 in this scenario, this would mean that a value is changed, which is not the aim of the formatter and may break some user's functionality.

                                If you wish to show 0 instead of -0, you can handle the onInitialized event as shown below:


                                onInitialized(e) { var val = e.component.option("value"); if (Math.round(val) === -0){ e.component.option("value", 0) } }


                                Show all comments
                                • Sebastian Marten 05.01.2018
                                  In the end, that is your call.

                                  I do however think that you are not taking your target audience into account. In my opinion, we use these components to provide an end user experience, so the target audience is the end user.
                                  Whether the behaviour is technically correct in an obscure usage in JavaScript, where -0 isn't the same as 0, it's irrelevant if real world usage is expected to be different.
                                • Sebastian Marten 05.01.2018
                                  Some more info.
                                  The company I work does a lot of work with numerical data. have checked with a number of people with maths degrees and others that work with financial data. The consensus is that the javascript behaviour is a computer artefact. Mathematically, there is no such things as zero.
                                  Which means that the display of -0.0 to end users is in fact wrong.
                                • Nikolai (DevExpress Support) 05.03.2018

                                  Hi Sebastian,

                                  Yes, it might not be correct from an end user point of view. I think that the issue is not so simple as it might seem at first glance. What if the value of your NumberBox will be used for calculating other values. For example, you have a second NumberBox which value is calculated by multiplying the first widget value by 2 and that value is not formatted or the second widget uses a different format precision. In this case, the second value will be -0.000000004  (-0.000000002* 2). This is the correct value. However, if the first NumberBox displayed 0.0 instead of -0.0, it would be strange for an end user to see the second value with the minus sign. What do you think?

                                • Sebastian Marten 05.03.2018
                                  Hi Nikolai, I don't agree. There is no such thing as -0 in the real world. Multiplying by 0 is 0. multiplying by -0 is also 0.

                                  If you need the kind of precision you're talking about, you would display it in both fields.
                                • Nikolai (DevExpress Support) 05.04.2018

                                  >>There is no such thing as -0 in the real world. Multiplying by 0 is 0. multiplying by -0 is also 0.

                                  It seems that we are talking about different issues. In your original example, you have the following code:
                                  $("#numberBox").dxNumberBox({ name: "sample", value: -0.000000002, format: "#,##0.0" });

                                  This code means that the NumberBox will display the "-0.000000002" value as "-0.0", which is only a representation form of the "-0.000000002" value. The widget keeps its value as is and it does not transform it in any way. If you execute the following code, you will get "-2e-9" instead of "-0.0" or "0.0":

                                  As far as I understand your idea, you wish to convert small numbers to 0. If so, set the dxNumberBox.value option to 0 instead of -0.000000002. For example, you can check values before setting the widget value. For instance, if the value is less than 0.09 then, set the value option to 0. 
                                  $("#numberBox").dxNumberBox({ name: "sample", value: Math.abs(yourValue) < 0.09 ? 0 : yourValue, format: "#,##0.0" });
                                • Sebastian Marten 05.04.2018
                                  Hi Nikolai,

                                  I really appreciate your help, but we were talking about the same thing. I'm not sure how else I can express myself to get it across. A lot of the replies have led to misunderstandings.

                                  My only intention is to get the original issue addressed, which is: 

                                  When dxNumberBox has negative values that round to 0, they are displayed as -0.

                                  I asked this question as to me this is clearly incorrect behaviour; a display value has to have meaning. Which -0 doesn't. -0 doesn't even exist. I also understand that -0.0 is presentational, which is even worse in a way, as it presents an artefact that exists only in javascript to end users, i.e. the real world.

                                  Think about this: If your bank balance was shown as -$0.00 because you owe a small fraction of a $, you'd question it, because it looks kinda funny...

                                  If you guys think your approach is right and it will stay like it is, please say so and I will work around it.

                                • Sebastian Marten 05.11.2018
                                  I'm assuming that you are just going to leave the current behaviour and will not comment on this ticket anymore? Would be nice to get a notification in this case..
                                • Nikolai (DevExpress Support) 05.14.2018

                                  Hi Sebastian,

                                  As I mentioned earlier, dxNumberBox does not round values. The format option is used for visual representation of the dxNumberBox.value option. If you check this option, it will not be changed. So, we are going to keep this behavior without any changes. I recommend using the workaround we suggested earlier.

                                  Let me know if you have any other questions.

                                • Sebastian Marten 05.14.2018
                                  I don't know where this went off track, but I have been talking about the Visual Representation of the number all along, which is clearly a formatted representation of the actual value, where rounding takes place if necessary for display purposes. Modified Sample where -0.05 is formatted and displayed as -0.1, which is clearly a rounded visual representation of -0.05.  This is an issue when -0, or any variation of -0, is displayed.

                                  I understand that the value stays the same, no matter what is shown, which means that the suggested workaround will not work, because I do not want to change the value.
                                • Nikolai (DevExpress Support) 05.15.2018


                                  I still cannot catch your idea. Let's take a look at the example. There are two editors: "number1" and "number2". The second editor depends on a value of the first one. The real "number1" value is "-0.0005" and it is displayed as "-0.0" according to the current format. The "number2" value is calculated as the first editor value multiplied by "1000000". So, the second value is displayed as "-500.0" with the minus sign. If dxNumberBox displayed "-0.0005" as "0.0", the second value would be with the minus sign (-500.0) due to the real value of the "number1" editor. So, I believe that this behavior will confuse users because multiplying a visually displayed "0.0" value by "1000000" gives "-500.0". Would you please share your thoughts regarding this case?

                                • Sebastian Marten 05.15.2018

                                  To illustrate this in a different way, I have attached a tiny Excel spreadsheet with your calculations and specified display decimal places (rounding the displayed value). It displays 0.0 and -500.0, while still holding the actual values (as seen by selecting the cell), so I don't think confusion is a factor, rather the -0.0 is confusing

                                  The -0 display happens only when using the math.round javascript function, as it's a javascript artefact. It has no place as a display value anywhere else, as there is no such thing as -0 anywhere else. Even the MDN presents a better solution on it's math.round page, which will not display -0. MDN math.round()

                                  I hope this makes sense.
                                • Nikolai (DevExpress Support) 05.16.2018


                                  Thank you for your file. I see that Excel displays numbers according to your requirements. However, this behavior may not meet the requirements of other users. So, we do not have plans to change it at the component level. We believe that this task should be implemented at the application level. I recommend that you change the text in the input element rendered by dxNumberBox as shown below:

                                  const correctText = function(component) { const val = component.option("value"); if (Math.round(val) === -0) { const inpt = component.element().find(".dx-texteditor-input"); inpt.val(inpt.val().replace("-", "")); } } $("#numberBox").dxNumberBox({ name: "sample", value: -0.000000002, format: "#,##0.0", onInitialized(e) { setTimeout(function() { correctText(e.component); }); }, onFocusOut: function(e) { correctText(e.component); } });


                                  The example shows this approach in action.

                                • Sebastian Marten 05.16.2018
                                  Fair enough, thanks.
                                • Nikolai (DevExpress Support) 05.17.2018
                                  You are always welcome!