Forums WoW Modding Discussion Miscellaneous [Archive] [C#] How do i convert from a string to double? [Resolved]

[Archive] [C#] How do i convert from a string to double? [Resolved]

[Archive] [C#] How do i convert from a string to double? [Resolved]

Pages (2): 1 2 Next
rektbyfaith
Administrator
0
06-01-2016, 12:12 AM
#1
Archived author: dashker • Posted: 2016-06-01T00:12:58+00:00
Original source

Like i said from example

in TextBox1.text I have 2.0

How i can got this value?
rektbyfaith
06-01-2016, 12:12 AM #1

Archived author: dashker • Posted: 2016-06-01T00:12:58+00:00
Original source

Like i said from example

in TextBox1.text I have 2.0

How i can got this value?

rektbyfaith
Administrator
0
06-01-2016, 04:57 AM
#2
Archived author: noc • Posted: 2016-06-01T04:57:43+00:00
Original source

like this ?

Int_Seconds = int.Parse(TextBox1.Text);
rektbyfaith
06-01-2016, 04:57 AM #2

Archived author: noc • Posted: 2016-06-01T04:57:43+00:00
Original source

like this ?

Int_Seconds = int.Parse(TextBox1.Text);

rektbyfaith
Administrator
0
06-01-2016, 05:02 AM
#3
Archived author: Kaev • Posted: 2016-06-01T05:02:33+00:00
Original source

Quote: 5 minutes ago, noc said:

like this ?

Int_Seconds = int.Parse(TextBox1.Text);
1. This is int, not double.

2. Just double.Parse wouldn't work, because it actually wants the number as 2,0 instead of 2.0

You can use this:

double.Parse("2.0", System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);

Also, don't forget to check it is really something like 2.0. A user could enter 2.a or something and your program will probably crash.
rektbyfaith
06-01-2016, 05:02 AM #3

Archived author: Kaev • Posted: 2016-06-01T05:02:33+00:00
Original source

Quote: 5 minutes ago, noc said:

like this ?

Int_Seconds = int.Parse(TextBox1.Text);
1. This is int, not double.

2. Just double.Parse wouldn't work, because it actually wants the number as 2,0 instead of 2.0

You can use this:

double.Parse("2.0", System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);

Also, don't forget to check it is really something like 2.0. A user could enter 2.a or something and your program will probably crash.

rektbyfaith
Administrator
0
06-01-2016, 08:53 AM
#4
Archived author: noc • Posted: 2016-06-01T08:53:28+00:00
Original source

Thank Kaev, you're right.

I found some informations here : http://stackoverflow.com/questions/13549...o-a-double

and here : http://stackoverflow.com/questions/43528...-to-double
rektbyfaith
06-01-2016, 08:53 AM #4

Archived author: noc • Posted: 2016-06-01T08:53:28+00:00
Original source

Thank Kaev, you're right.

I found some informations here : http://stackoverflow.com/questions/13549...o-a-double

and here : http://stackoverflow.com/questions/43528...-to-double

rektbyfaith
Administrator
0
06-01-2016, 09:33 AM
#5
Archived author: dashker • Posted: 2016-06-01T09:33:36+00:00
Original source

So i will show you the problem, i am parsing a double, converting to string bubt with the double format

double text = double.Parse(ScaleBox.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);

string result = number[0] + "," + number[1]+ "," + number[2] + "," + number[3] + "," + text;
rektbyfaith
06-01-2016, 09:33 AM #5

Archived author: dashker • Posted: 2016-06-01T09:33:36+00:00
Original source

So i will show you the problem, i am parsing a double, converting to string bubt with the double format

double text = double.Parse(ScaleBox.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);

string result = number[0] + "," + number[1]+ "," + number[2] + "," + number[3] + "," + text;

rektbyfaith
Administrator
0
06-01-2016, 10:25 AM
#6
Archived author: Kaev • Posted: 2016-06-01T10:25:56+00:00
Original source

Quote: 50 minutes ago, dashker said:

So i will show you the problem, i am parsing a double, converting to string bubt with the double format

double text = double.Parse(ScaleBox.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);

string result = number[0] + "," + number[1]+ "," + number[2] + "," + number[3] + "," + text;
Does it work as you wanted or not? You just posted a snippet without any informations.

Also, just for future coding style: If number[] is a array of int or double or smth like that, make sure to write number[0].ToString().
rektbyfaith
06-01-2016, 10:25 AM #6

Archived author: Kaev • Posted: 2016-06-01T10:25:56+00:00
Original source

Quote: 50 minutes ago, dashker said:

So i will show you the problem, i am parsing a double, converting to string bubt with the double format

double text = double.Parse(ScaleBox.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);

string result = number[0] + "," + number[1]+ "," + number[2] + "," + number[3] + "," + text;
Does it work as you wanted or not? You just posted a snippet without any informations.

Also, just for future coding style: If number[] is a array of int or double or smth like that, make sure to write number[0].ToString().

rektbyfaith
Administrator
0
06-01-2016, 12:41 PM
#7
Archived author: dashker • Posted: 2016-06-01T12:41:40+00:00
Original source

Quote: 2 hours ago, Kaev1695989297 said:

Does it work as you wanted or not? You just posted a snippet without any informations.

Also, just for future coding style: If number[] is a array of int or double or smth like that, make sure to write number[0].ToString().
Tes i have it hahaha but when i put it in a text box for example the "2.0" is 2 so i don't know if i have to add it into the string or another thing
rektbyfaith
06-01-2016, 12:41 PM #7

Archived author: dashker • Posted: 2016-06-01T12:41:40+00:00
Original source

Quote: 2 hours ago, Kaev1695989297 said:

Does it work as you wanted or not? You just posted a snippet without any informations.

Also, just for future coding style: If number[] is a array of int or double or smth like that, make sure to write number[0].ToString().
Tes i have it hahaha but when i put it in a text box for example the "2.0" is 2 so i don't know if i have to add it into the string or another thing

rektbyfaith
Administrator
0
06-01-2016, 12:46 PM
#8
Archived author: dashker • Posted: 2016-06-01T12:46:50+00:00
Original source

int[] number = new int[15];
number[0] = int.Parse(EntryBox.Text);
number[1] = int.Parse(ModelBox.Text);
number[2] = int.Parse(SoundBox.Text);
number[3] = int.Parse(DisplayInfoExtraBox.Text);
double scale = double.Parse(ScaleBox.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);
string result = number[0] + "," + number[1]+ "," + number[2] + "," + number[3] + "," + scale;
ShitBox.Text = result;

So i don't know how to handle the double so my head is exploding
rektbyfaith
06-01-2016, 12:46 PM #8

Archived author: dashker • Posted: 2016-06-01T12:46:50+00:00
Original source

int[] number = new int[15];
number[0] = int.Parse(EntryBox.Text);
number[1] = int.Parse(ModelBox.Text);
number[2] = int.Parse(SoundBox.Text);
number[3] = int.Parse(DisplayInfoExtraBox.Text);
double scale = double.Parse(ScaleBox.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);
string result = number[0] + "," + number[1]+ "," + number[2] + "," + number[3] + "," + scale;
ShitBox.Text = result;

So i don't know how to handle the double so my head is exploding

rektbyfaith
Administrator
0
06-02-2016, 03:00 PM
#9
Archived author: dashker • Posted: 2016-06-02T15:00:29+00:00
Original source

Anyone Help me please?

Thanks for answers
rektbyfaith
06-02-2016, 03:00 PM #9

Archived author: dashker • Posted: 2016-06-02T15:00:29+00:00
Original source

Anyone Help me please?

Thanks for answers

rektbyfaith
Administrator
0
06-02-2016, 03:17 PM
#10
Archived author: Skarn • Posted: 2016-06-02T15:17:19+00:00
Original source

Isn't there a way to make a TextField return a double or a float without any conversion?
rektbyfaith
06-02-2016, 03:17 PM #10

Archived author: Skarn • Posted: 2016-06-02T15:17:19+00:00
Original source

Isn't there a way to make a TextField return a double or a float without any conversion?

Pages (2): 1 2 Next
Recently Browsing
 1 Guest(s)
Recently Browsing
 1 Guest(s)