Decimal point in C # calculator

AHHHHH ok, that turns me on.

Why, when my decimal point is in the wrong place, for example,

If I have line 567 in the text box and press the decimal button, I would expect (or I want) the text box to change to 567. but instead I get .567

It only gets to the right place when I add another number, for example. if I had the number 4, then right after the execution above I would get 567.4

Edit:

Here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Calculator
{
    public partial class frmCurrencyCalc : Form
    {
        public frmCurrencyCalc()
        {
            InitializeComponent();
        }

        private void cmdZero_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "0";
            }
            else
            {
                txtScreen.AppendText("0");
            }
        }
        private void cmd1_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "1";
            }
            else
            {
                txtScreen.AppendText("1");
            }
        }

        private void cmdTwo_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "2";
            }
            else
            {
                txtScreen.AppendText("2");
            }
        }

        private void cmdThree_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "3";
            }
            else
            {
                txtScreen.AppendText("3");
            }
        }

        private void cmdFour_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "4";
            }
            else
            {
                txtScreen.AppendText("4");
            }
        }

        private void cmdFive_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "5";
            }
            else
            {
                txtScreen.AppendText("5");
            }
        }

        private void cmdSix_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "6";
            }
            else
            {
                txtScreen.AppendText("6");
            }
        }

        private void cmdSeven_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "7";
            }
            else
            {
                txtScreen.AppendText("7");
            }
        }

        private void cmdEight_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "8";
            }
            else
            {
                txtScreen.AppendText("8");
            }
        }

        private void cmdNine_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "9";
            }
            else
            {
                txtScreen.AppendText("9");
            }
        }

       private void cmdDecimal_Click(object sender, EventArgs e)
      {
          txtScreen.AppendText(".");
          cmdDecimal.Enabled = false;
      }


        private void cmdCancel_Click(object sender, EventArgs e)
        {
            txtScreen.Text = "0";
            cmdDecimal.Enabled = true;
        }
    }
}
+3
source share
6 answers

My advice is to set TextAlignto the right, but leave it RightToLeftat No.

Edit: Having said that, this problem may not be related to these settings.

, , 2009 Visual Studio 2008 Windows Vista. , Visual Studio Windows XP.

Visual Studio/.NET 3.5 Service Pack 1, , .

+1

RightToLeft . MSDN,

RightToLeft , , , . RightToLeft..::. , .

, false, TextAlign Right, .

+1

- -. - . . .

+1

, :

private void AddDecimal()
{
    txtScreen.SelectionLength = txtScreen.TextLength;
    txtScreen.SelectedText += ".";
}

( , , ... .)

0

, .

:

txtScreen. = true;

, , . - :

txtScreen.AppendText( "00" ).

, .

. , . :

decimal value = 567;
txtScreen.Text = value.ToString("0.00");

, , 567.00.1 ..

0

, .

- . , , , ( ) ... , ...

,

0

Source: https://habr.com/ru/post/1733965/


All Articles