转换成数字 [英] CONVERSION strin to number

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

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class converstion
{

    public static void Main(string[] args)
{
string s1="sidd";
string s2="siddh";



double da=Convert.ToDouble(s1);
double d=Convert.ToDouble(s2);
Console.WriteLine("converte string is={0}",da);
Console.WriteLine("converte string is={1}", d);

}

}


它会成功编译但无法运行...错误未处理的Exceptuon:System.FormatException:输入字符串不在正确的formate中.


it compile successfullly but not run...error "Unhandel Exceptuon:System.FormatException:input string was not in a correct formate

推荐答案

异常是正确的.如何解决此问题?将"sidd"之类的字符串转换为双精度.
尝试将"10"转换为双精度,它将起作用.
Exception is correct. How can you convert a string like "sidd" to a double.
Try converting "10" to double, it will work.


如果您要将字符串转换为数字,则字符串的值必须为number.

例如:string str ="445"; //可能
字符串str ="abcd"; //不可能
If u want to convert a string to a number , the values of the string must be number.

Eg : string str = "445"; // Possible
string str = "abcd"; // Not Possible


您好,Siddharth,
尝试了解.您不能将这种类型的字符串值更改为double.因为这是真实的字符串.您如何将自己的名字改成两倍.这可能吗.你可以做到的...


Hi Siddharth,
try to understand. you can not change this type of string value into double. beacuse this is real string. How can you change your name into double. is this possible. You can do this...


String str="50";
double doubleValue=Convert.ToDouble(str);



现在它将使您返回双值....

关于Rahul



and now it will return you to a double value....

Regards Rahul


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

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