I'm trying to create a simple application which lets you enter your salary and then when the button is pressed the taxes on the salary will ben calculated and shown. The app works, but I want the results to be forced showing two decimals. I've tried different codes, but it won't do it. Math.Round (x , 2); is most obvious, but doesn't work. Can someone tell me hat I'm doing wrong?
My code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
String Text = Textbox.Text;
Double Salaris = Convert.ToDouble(Text);
Double Belasting;
Double Schijf1;
Double Schijf2;
Double Schijf3;
Double Schijf4;
if (Salaris <= 6800)
{
Belasting = Math.Round (((Salaris / 100) * 35.70) ,2);
Schijf1 = Math.Round (((Salaris / 100) * 35.70) ,2);
S1uitkomst.Content = Schijf1;
S2uitkomst.Content = 0000.00;
S3uitkomst.Content = 0000.00;
S4uitkomst.Content = 0000.00;
}
else if (Salaris > 6800 && Salaris < 21800)
{
Belasting = Math.Round (((6800 / 100) * 35.70) + (((Salaris - 6800) / 100) * 37.05) ,2);
Schijf1 = Math.Round (((6800 / 100) * 35.70) ,2);
Schijf2 = Math.Round ((((Salaris - 6800) / 100) * 37.05) ,2);
S1uitkomst.Content = Schijf1;
S2uitkomst.Content = Schijf2;
S3uitkomst.Content = 0000.00;
S4uitkomst.Content = 0000.00;
}
else if (Salaris > 21800 && Salaris < 48100)
{
Belasting = Math.Round (((6800 / 100) * 35.70) + ((15000 / 100) * 37.05) + (((Salaris - 21800) / 100) * 50.00) ,2);
Schijf1 = Math.Round (((6800 / 100) * 35.70), 3);
Schijf2 = Math.Round (((15000 / 100) * 37.05) ,3);
Schijf3 = Math.Round ((((Salaris - 21800) / 100) * 50.00) ,3);
S1uitkomst.Content = Schijf1;
S2uitkomst.Content = Schijf2;
S3uitkomst.Content = Schijf3;
S4uitkomst.Content = 0000.00;
}
else
{
Belasting = Math.Round (((6800 / 100) * 35.70) + ((15000 / 100) * 37.05) + ((26300 / 100) * 50.00) + (((Salaris - 48100) / 100) * 60.00) ,2);
Schijf1 = Math.Round (((6800 / 100) * 35.70), 2);
Schijf2 = Math.Round (((15000 / 100) * 37.05) ,2);
Schijf3 = Math.Round (((26300 / 100) * 50.00), 2);
Schijf4 = Math.Round ((((Salaris - 48100) / 100) * 60.00) ,2);
S1uitkomst.Content = Schijf1;
S2uitkomst.Content = Schijf2;
S3uitkomst.Content = Schijf3;
S4uitkomst.Content = Schijf4;
}
Totaal.Content = Belasting;
}
private void Textbox_TextChanged(object sender, TextChangedEventArgs e)
{
}
}
}