❔ Wrong calculation output
So this is my final code:
The formulas are correct, but there has to be some weird conversion mistake I made because the result which comes for
Bezugspreis
is completely off.
Anyone an idea where i made a mistake?
Here an example entry and which result should come out:
menge.Text = 50
listenpreis.Text = 4
mindermengenzuschlag.Text = 2.5
rabatt.Text = 0
skonto.Text = 0
transportkosten.Text = 4.95
Calculated values:
listeneinkaufspreis = 202.5
lieferrabatt = 0
lieferskonto = 0
transportkostenBerechnet = 4.95
And the correct final result:
bezugspreis = 207.45
I get the wrong result (750)15 Replies
use the debugger?
$debug
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
also, its conventional to name all your variables and stuff in english, even if the app uses... german? dutch? localization in the frontend
to make it maybe a little easier to debug, create the object separately, then add it to the list. Then you might be able to observe one instance of the
DataItem
easier than scrolling through the collection (VergleichDataGrid.Items
) more easily.Yeah German. I want to make it English but our teachers force us to use German so they understand the variables etc better
kek
but yeah, as james suggested, do things in a few more inbetween steps so you can inspect the values with the debugger
that lets you check that each variable has the value you expect as you go
But is there no obvious conversion error in my code which states directly that the result cannot be right
Because it is so far off
some value somewhere isnt getting the value you expect. thats it.
I'm not gonna do the math on this one when the answer so very clearly is: "use the debugger" 😛
Ok I will check it. Because I know the formulas are correct (tested before with JavaScript)
could be the classic
.
vs ,
with decimalI only used . So far. I will test , in a Bit
Okay @Pobiega, you were right. With commas as TextBox input every calculation is correct.
How could I also make dots work the same way?
this is because what number is the decimal separator is "culture specific"
you can specify what culture to parse a number as, but there is no good way to support both at the same time, because what does
30,40.50
parse as?I mean could I not just use the replace method to replace all dots with commas before it is being parsed
is
30,40,50
easier to parse? 🙂
I'd suggest removing the ability to write everything except numbers and .
and then use a culture you know handles dots
Add a preview text input event. Like so:alternatively, and probably better, is to make a Behavior for this<TextBox PreviewTextInput="PreviewTextInput" />.
Then inside that set thee.Handled
property if the text isn't allowed.e.Handled = !IsTextAllowed(e.Text)
;
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.