开发者

Number to Turkish text app

开发者 https://www.devze.com 2023-01-25 18:12 出处:网络
I m Trying to convert a number entered in the text box post.But I can not find the right reasons, does not work.Are you also please have a look.Thank you in advance!

I m Trying to convert a number entered in the text box post.But I can not find the right reasons, does not work.Are you also please have a look.Thank you in advance!

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;

namespace NumberToText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void NumberControl()
        {
            if ((txtNumber.Text.Length>7))
            {
                MessageBox.Show("Please enter a smaller number");
            }
        }
        public void ReadNumber()
        {


            try
            {
                int ones, tens, hundreds, thousands, tenthousands, hundredthousands, 

millions;
                int number = Convert.ToInt32(txtNumber.Text);

                int[] array=new int[7];



                for (int j = 0; j < txtNumb开发者_如何学Pythoner.Text.Length; )  
                {

                    array[j] = (number / (10 ^ (txtNumber.Text.Length - 

(txtNumber.Text.Length - j)))) % 10;
                    j += 1;
                }
                if (txtSayi.Text.Length != 7) 
                {
                    for (int i = 6; i >= txtNumber.Text.Length; )
                    {
                        dizi[i] = 0;
                        i-=1;
                    }
                }

                  ones = array[0];
                  tens = array[1];
                  hundreds = array[2];
                  thousands = array[3];
                  tenthousands = array[4];
                  hundredthousands = array[5];
                  millions = array[6];

                //Converting to numbers in TURKISH Text

                string[] a_ones = { "", "Bir", "İki", "Üç", "Dört", "Beş", "Altı", 

"Yedi", "Sekiz", "Dokuz" };
                string[] a_tens = { "", "On", "Yirmi", "Otuz", "Kırk", "Elli", 

"Altmış", "Yetmiş", "Seksen", "Doksan" };
                string[] a_hundreds = { "", "Yüz", "İkiyüz", "Üçyüz", "Dörtyüz", 

"Beşyüz", "Altıyüz", "Yediyüz", "Sekizyüz", "Dokuzyüz" };
                string[] a_thousands = { "", "Bin", "İkibin", "Üçbin", "Dörtbin", 

"Beşbin", "Altıbin", "Yedibin", "Sekizbin", "Dokuzbin" };
                string[] a_tenthousands = { "", "On", "Yirmi", "Otuz", "Kırk", 

"Elli", "Altmış", "Yetmiş", "Seksen", "Doksan" };
                string[] a_hundredthousands = { "", "Yüz", "İkiyüz", "Üçyüz", 

"Dörtyüz", "Beşyüz", "Altıyüz", "Yediyüz", "Sekizyüz", "Dokuzyüz" };
                string[] a_millions = { "", "Birmilyon", "İkimilyon", "Üçmilyon", 

"Dörtmilyon", "Beşmilyon", "Altımilyon", "Yedimilyon", "Sekizmilyon", "Dokuzmilyon" 

};

                lblText.Text = a_millions[millions] + " " + a_hundredthousands

[hundredthousands] + a_tenthousands[tenthousands] + " " + a_thousands[thousands] + "  

" + a_hundreds[hundreds] + " " + a_tens[tens] + " " + a_ones[ones];

            } 
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message.ToString());
            }
        }




        private void btnConvert_Click(object sender, EventArgs e)
        {
            NumberControl();
            ReadNumber();

        }

    }
}


for (int j = 0; j < txtNumber.Text.Length; )  
{
    array[j] = (number / (10 ^ (txtNumber.Text.Length - (txtNumber.Text.Length - j)))) % 10;
    j += 1;
}

(txtNumber.Text.Length - (txtNumber.Text.Length - j)) is j, so:

for (int j = 0; j < txtNumber.Text.Length; j += 1)  
{
    array[j] = (number / (10 ^ j)) % 10;
}

You're XOR'ing 10 with j?

Also, "Sekizmilyon" is not a word. You need a put a space in between.


It looks like you're trying to calculate a power of 10 with ^ when you probably mean Math.Pow. Using the reduction aib suggested, your line:

array[j] = (number / (10 ^ (txtNumber.Text.Length - (txtNumber.Text.Length - j)))) % 10;

becomes:

array[j] = (number / (int)Math.Pow(10, j)) % 10;

A couple of other suggestions:

  1. Change NumberControl to return a bool so you can skip the call to ReadNumber if the entered number is too large. Currently it goes into ReadNumber even if the number is more than 7 digits, which results in an array out of bounds error

  2. The block of code starting with if (txtSayi.Text.Length != 7) seems redundant.

0

精彩评论

暂无评论...
验证码 换一张
取 消