本文介绍了如何将Int转换为119或123到100,20,3,100,19的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你好每个身体我需要转换数字c# 喜欢 100为100 101是100,0,1 119为100,0,19 123为100,20,3 1001为1000, 0,0,1 1020为1000,0,20 1019为100,0,0,19 谢谢 我的代码 i认为它可以更简单 使用系统; 使用 System.Collections.Generic; 使用 System.ComponentModel; 使用 System.Data; 使用 System.Drawing; 使用 System.Linq; 使用 System.Text; 使用 System.Windows.Forms; 使用 System.Media; 使用 System.Threading; 命名空间 WindowsFormsApplication1 { public 部分 类 Form1:表格 { 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 \ EnglishWindows + rem4 + 。wav); Rem4Siound.Play(); Thread.Sleep( 600 ); SoundPlayer Rem3Siound = new SoundPlayer( @ C:\ SendWirlessLed\English Sound \ + rem3 + .WAV); Rem3Siound.Play(); Thread.Sleep( 600 ); 如果(rem1!= 0 ) { SoundPlayer Rem1Siound = new SoundPlayer( @ C:\ SendWirlessLed \English Sound \ + rem1 + 的.wav); Rem1Siound.Play(); Thread.Sleep( 600 ); } { SoundPlayer andSound = 新 SoundPlayer( @ C:\ SendWirlessLed\English Sound\and.wav); andSound.Play(); Thread.Sleep( 700 ); } 如果(rem2!= 0 ) { SoundPlayer Rem2Siound = new SoundPlayer( @ C:\ SendWirlessLed \English Sound \ + rem2 + .wav ); Rem2Siound.Play(); Thread.Sleep( 600 ); } } 其他 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); } } 如果(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 ); } } 其他 如果(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 ); } } } } 可以有人帮我解决方案 JavaScript function NumBreakDown(nums) { var arr = nums.toString( ).split(' '); var temp = []; while (my = arr.shift()) { temp.push(my + ' 000000' .substr( 0 ,arr.length) ); } 如果(temp [temp.length-1] == '' 0') { temp.pop(); } return temp; } 1763 => ['''1000'',''700'',''60'',''3'']; 1450 => ['''1000'',''400'',''50'']; 123为100,20,3 1020将是1000,0,20 1019为100,0,0,19 好​​,第一行和第二行似乎没问题,但最后一行让我很困惑, 你的意思是:1000,0,19?或者,1000,0,0,19 ??? 也许,这可以通过以下方式完成: i == 1,2,3,.... .. X = pow(10,i)*(n%pow(10,i) )); 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,19123 to be 100,20,3 1001 to be 1000,0,0,11020 to be 1000,0,201019 to be 100,0,0,19thanks this my code i think i t can be more simpleusing 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 解决方案 JavaScriptfunction 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''];123 to be 100,20,3 1020 to be 1000,0,201019 to be 100,0,0,19well, 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)); 这篇关于如何将Int转换为119或123到100,20,3,100,19的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 08:51