救命!!!字符串转换 [英] help!!! string convert

查看:65
本文介绍了救命!!!字符串转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hiii,

我该怎样做我的项目?

hiii,
how can i do my project?

string str1="4567995244...4457";
string str2="1458795568...85498";

str1+str2; // addition
str1-str2; // differance
str1*str2; // multiplication
str1/str2; // division





注意:我们也不使用biginteger类

我们不使用算术运算符



note: we dont use biginteger class also
we dont use arithmetic operatiors

推荐答案

如果我理解你的问题,你首先必须将数据类型更改为可在计算中使用的内容。例如:

If I understood your question correctly, you first have to change the data type to something you can use in calculation. For example:
int a = int.Parse("123") + int.Parse("456");



当然你会在 TryParse 中使用变量而不是常量字符串。


Of course you would use variables inside TryParse instead of constant strings.


如果BigInteger不够好,请在这里查看: http://www.codeplex.com/Wikipage?ProjectName=sine [ ^ ]
If BigInteger is not good enough, look around here: http://www.codeplex.com/Wikipage?ProjectName=sine[^]






试试这个:

Hi,

Try this:
string str1="4567995244...4457";
string str2="1458795568...85498";

decimal d1 = Convert.ToDecimal(str1);
decimal d2 = Convert.ToDecimal(str2);

decimal addition = d1+d2; // addition
decimal difference = d1-d2; // difference
decimal multiplication = d1*d2; // multiplication
decimal division = d1/d2; // division









我已阅读你的评论。所以,这是我的编辑。





I''ve read your comment. So, this is my edit.

Orhss写道:

注意:我们也不使用biginteger类

note: we dont use biginteger class also



我认为没有其他选择,然后使用 BigInteger 。添加对System.Numerics.dll的引用,使用 System.Numerics;


I think there''s no other option then using a BigInteger. Add a reference to System.Numerics.dll, add

添加

 to the top of your code file, and then use this code:
BigInteger b1 = BigInteger.Parse(str1);
BigInteger b2 = BigInteger.Parse(str2);

BigInteger addition = b1 + b2;
BigInteger difference = b1 - b2;
BigInteger multiplication = b1 * b2;
BigInteger division = b1 / b2;



希望这会有所帮助。


Hope this helps.


这篇关于救命!!!字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆