本文介绍了如何将净工资转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 早上好,上午2点和我累了哈哈。 无效 convertNetPay( float netPay, char * netPayString) { int numHuns,numTens,numOnes; char OnesTable [ 9 ] [ 8 ] = { 一个, 两个, 三个, 四, 五, 六, 七, Eight, Nine}; char ResultString [10 + 1]; char TensTable [ 9 ] [ 8 ] = { 十, 二十, 三十, 四十, Fifty, Sixty, 七十, Eighty, Ninety}; char TeensTable [ 9 ] [ 10 ] { 十一, 十二, 十三 , 十四, 十五, 十六, 十七, 十八, 十九}; float 美分; 美分= netPay - int (netPay); strcpy(netPayString, )的总和; numHuns = int (netPay)/ 100 ; if (numHuns > 0 ) { strcat(netPayString,OnesTable [numHuns-1]); strcat(netPayString, Hundred); } int remainder = int (netPay)% 100 ; / * if(remainder == 0) { //做点什么} * / 如果((余数> = 11 )||(余数< = 19 )) { strcat(netPayString,TeensTable [remainder -11]); } 其他 { numTens = int (netPay)% 100 / 10 ; numOnes = int (netPay)% 100 % 10 ; if (numTens > 0 ) { strcat(netPayString,TensTable [numTens -1]); strcat(netPayString, - ); } if (numOnes > 0 ) { strcat(netPayString,OnesTable [numOnes-1]); strcat(netPayString, 美元和); } 美分=美分+ 0 。 005 ; 美分=美分* 100 ; sprintf(ResultString, %d, INT (分)); strcat(netPayString,ResultString); } } 基本上,我必须转换netpay(浮点数到字符串)。 理论上如果我有666.66,我的程序应输出六百六十六和六十六美元的总和。 感谢任何帮助,谢谢!解决方案 谷歌是你的朋友:好好经常拜访他。他可以比在这里发布问题更快地回答问题... 一次非常快速的搜索提供了超过200万次点击:数字到英文单词c ++ [ ^ ] 将来,请尝试自己做至少基础研究,不要浪费你的时间或我们的时间。 GOOD MORNING, ITS 2AM AND IM TIRED LOL.void convertNetPay(float netPay, char *netPayString){ int numHuns, numTens, numOnes; char OnesTable[9][8]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"}; char ResultString[10+1]; char TensTable[9][8] = {"Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"}; char TeensTable[9][10] {"Eleven","Twelve","Thirteen","fourteen","fifteen","Sixteen","Seventeen","Eighteen","Nineteen"}; float cents; cents = netPay - int(netPay); strcpy(netPayString,"The sum of "); numHuns = int(netPay) / 100; if (numHuns > 0) { strcat(netPayString,OnesTable[numHuns-1]); strcat(netPayString," Hundred "); } int remainder = int(netPay) % 100; /*if (remainder ==0) { //do something }*/ if ((remainder>=11) || (remainder<=19)) { strcat(netPayString, TeensTable[remainder -11]); } else{ numTens = int(netPay) % 100 / 10; numOnes = int(netPay) % 100 % 10; if (numTens > 0) { strcat(netPayString,TensTable[numTens -1]); strcat(netPayString," - "); } if (numOnes > 0) { strcat(netPayString,OnesTable[numOnes-1]); strcat(netPayString," Dollars and "); } cents = cents + 0.005; cents = cents * 100; sprintf(ResultString,"%d",int(cents)); strcat(netPayString,ResultString); }}BASICALLY, I have to convert netpay (float to string).Theoretically if I have 666.66, my program here should output the sum of "six hundred sixty-six and 66/100 dollars". Any help is appreciated, thank you! 解决方案 Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...A very quick search gave over 2 million hits: number to english words c++[^]In future, please try to do at least basic research yourself, and not waste your time or ours. 这篇关于如何将净工资转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 10:02