Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello every body i need to convert number c#
like
100 to be 100
101 to be 100 ,0,1
119 to be 100,0,19
123 to be 100,20,3
1001 to be 1000,0,0,1
1020 to be 1000,0,20
1019 to be 100,0,0,19
thanks

this my code
i think i t can be more simple
C#
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.Media;
using System.Threading;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {



            Int32 rem1 = 0;//
            Int32 rem2 = 0; ;
            Int32 rem3 = 0;
            Int32 rem4 = 0;
            //string Patiant = System.Convert.ToString(PAT.Text);

            string  Patiant_no = System.Convert.ToString(PAT.Text); ;
            if (Patiant_no.Length == 4)
            {
                rem4 = System.Convert.ToInt32(Patiant_no.Substring(0, 1) + "000");

                rem3 = (System.Convert.ToInt32(Patiant_no) - (rem4));
                 rem3 = System.Convert.ToInt32(Patiant_no.Substring(0, 1) + "00");

                 rem2 = (System.Convert.ToInt32(Patiant_no) - (rem4) - (rem3));

                if (System.Convert.ToString(rem2).Length == 1)
                {

                    rem1 = 0;
                    //  rem2 = 0;
                }
                else
                {


                    rem1 = 0;
                    if (rem2.ToString().Substring(1, 1) != "0")
                    {
                        if (rem2 <= 19 && rem2 >= 11)
                        {
                            rem1 = 0;

                        }
                        else
                        {
                            rem1 = System.Convert.ToInt32(rem2.ToString().Substring(1, 1));
                            rem2 = System.Convert.ToInt32(rem2.ToString().Substring(0, 1) + "0");


                        }

                    }

                }
            }

            else if (Patiant_no.Length == 3)
            {
                rem3 = System.Convert.ToInt32(Patiant_no.Substring(0, 1) + "00");

                rem2 = (System.Convert.ToInt32(Patiant_no) - (rem3));

                if (System.Convert.ToString(rem2).Length == 1)
                {

                    rem1 = 0;
                    //  rem2 = 0;
                }
                else
                {


                    rem1 = 0;
                    if (rem2.ToString().Substring(1, 1) != "0")
                    {
                        if (rem2 <= 19 && rem2 >= 11)
                        {
                            rem1 = 0;

                        }
                        else
                        {
                            rem1 = System.Convert.ToInt32(rem2.ToString().Substring(1, 1));
                            rem2 = System.Convert.ToInt32(rem2.ToString().Substring(0, 1) + "0");


                        }

                    }

                }


                SoundPlayer Rem4Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem4 + ".wav");

                Rem4Siound.Play();

                Thread.Sleep(600);


                SoundPlayer Rem3Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem3 + ".wav");

                Rem3Siound.Play();

                Thread.Sleep(600);


                if (rem1 != 0)
                {

                    SoundPlayer Rem1Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem1 + ".wav");

                    Rem1Siound.Play();

                    Thread.Sleep(600);

                }



                {
                    SoundPlayer andSound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\and.wav");

                    andSound.Play();

                    Thread.Sleep(700);
                }

                if (rem2 != 0)
                {
                    SoundPlayer Rem2Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem2 + ".wav");

                    Rem2Siound.Play();

                    Thread.Sleep(600);

                }



            }

            else if (Patiant_no.Length == 2)
            {
                rem3 = 0;


                rem2 = System.Convert.ToInt32(Patiant_no);

                if (rem2.ToString().Substring(1, 1) != "0")
                {
                    if (rem2 <= 19 && rem2 >= 11)
                    {

                        rem1 = 0;

                    }
                    else
                    {
                        rem1 = System.Convert.ToInt32(rem2.ToString().Substring(1, 1));
                        rem2 = System.Convert.ToInt32(rem2.ToString().Substring(0, 1) + "0");


                    }



                }

                if (rem1 != 0)
                {
                    SoundPlayer Rem1Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem1 + ".wav");

                    Rem1Siound.Play();

                    Thread.Sleep(700);

                    {
                        SoundPlayer andSound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\and.wav");

                        andSound.Play();

                        Thread.Sleep(700);
                    }


                }








                if (rem2 != 0)
                {
                    SoundPlayer Rem2Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem2 + ".wav");

                    Rem2Siound.Play();

                    Thread.Sleep(700);
                }

            }

            else if (Patiant_no.Length == 1)
            {
                rem3 = 0;
                rem2 = 0;
                rem1 = System.Convert.ToInt32(Patiant_no);
                SoundPlayer Rem1Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem1 + ".wav");

                Rem1Siound.Play();

                Thread.Sleep(1000);
            }





        }
    }
}


can Someone help me
Posted
Updated 23-Apr-12 22:15pm
v4
Comments
Dr.Walt Fair, PE 23-Apr-12 22:01pm    
I thought you were separating digits by powers of ten until I saw your 3rd, 6th and 7th examples. If you can you explain the logic behind those, the algorithm should be straight forward and coding will then follow.
Mohamed_Alex 23-Apr-12 22:12pm    
i update the question now you can see it
i have a sound system that should read number and i record the wav file like 1.wav to 19 and 20.wav ,30.wav ,40.wav until 100
and 200 300 400 until 1000
Bernhard Hiller 24-Apr-12 5:45am    
You can find code for "converting numbers to text/words". Use that and adjust a little for playing your sound files instead of creating the output string.

JavaScript
JavaScript
function NumBreakDown(nums)
{
        var arr = nums.toString().split('');
        var temp = [];

        while(my = arr.shift())
        {
            temp.push(my+'000000'.substr(0, arr.length));
        }

        if(temp[temp.length-1] == '0')
        {
            temp.pop();
        }

        return temp;
}


1763 => ['1000', '700', '60', '3'];
1450 => ['1000', '400', '50'];
 
Share this answer
 
Comments
Maciej Los 18-Apr-13 6:21am    
+5
123 to be 100,20,3
1020 to be 1000,0,20
1019 to be 100,0,0,19

well, the first one and two lines seems ok, but the last line makes me confused,
do you mean: 1000, 0, 19? or, 1000, 0, 0, 19???

maybe, this could be done as below:


i == 1,2,3,.... ..
X = pow(10, i) * (n % pow(10,i));
 
Share this answer
 
v2
Comments
Mohamed_Alex 23-Apr-12 22:02pm    
1019 to be 1000,0,0,19
Dr.Walt Fair, PE 23-Apr-12 22:18pm    
So what algorithm is used to determine that 1020 -> 1000, 0, 20 while 1019 -> 1000, 0, 0, 19? I don't see any easily inferred pattern there.
Mohamed_Alex 23-Apr-12 22:24pm    
please see my code that i update it in the question if any of number rem1 or rem2 or rem3 is 0 no voice will send
Dr.Walt Fair, PE 23-Apr-12 22:35pm    
So, is the algorithm as follows? {1000*a, 100*b, 20*c, d} where a = N div 1000, b = (N - 1000*a) div 100, c = (N - 1000*a - b*100) div 20, d = N mod 20, where div represents an integer division and mod is the modulus operator.
Mohamed_Alex 23-Apr-12 22:42pm    
first thanks for you reply
second as i tell you before i need to play the sound like 100 and 23
or 1000 and 20
but im my code i have some problem like 119 it should be 100 and 19
are you got it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900