12,070,030 members (28,859 online)
Rate this:
See more:
Hello,

looking for a way to convert "10/10.00" to decimal.
Posted 29-Apr-13 12:42pm
bobb024396
ThePhantomUpvoter 29-Apr-13 17:47pm

Well the obvious thing to do would be to simply do the math....
bobb024 29-Apr-13 18:00pm

I am looking to compare to numbers and currently I have

if (FractionToDouble(parse.salePriceValue) > FractionToDouble(parse.regularPriceValue))
{
rejectedList.Add(data[0] + ", Regular Price cannot be Higher than Sale Price");
createSign = false;
}

public static double FractionToDouble(string fraction)
{
double result;

if (double.TryParse(fraction, out result))
{
return result;
}

string[] split = fraction.Split(new char[] { ' ', '/' });

if (split.Length == 2 || split.Length == 3)
{
int a, b;

if (int.TryParse(split[0], out a) && int.TryParse(split[1], out b))
{
if (split.Length == 2)
{
return (double)a / b;
}

int c;

if (int.TryParse(split[2], out c))
{
return a + (double)b / c;
}
}
}

throw new FormatException("Not a valid fraction.");
}
Dave Kreskowiak 29-Apr-13 18:37pm

And the problem would be ...... ?

Rate this:

Solution 1

```public static decimal FractionToDouble(string fraction)
{
decimal result;

if (decimal.TryParse(fraction, out result))
{
return result;
}

string[] split = fraction.Split(new char[] { ' ', '/' });

if (split.Length == 2 || split.Length == 3)
{
decimal a, b;

if (decimal.TryParse(split[0], out a) && decimal.TryParse(split[1], out b))
{
if (split.Length == 2)
{
return (decimal)b / a;
}

int c;

if (int.TryParse(split[2], out c))
{
return a + (decimal)b / c;
}
}
}

throw new FormatException("Not a valid fraction.");
}
public static int ReadAllBytesFromStream(Stream stream, byte[] buffer)
{
// Use this method is used to read all bytes from a stream.
int offset = 0;
int totalCount = 0;
while (true)
{
{
break;
}
}
}```

Top Experts
Last 24hrsThis month
 CHill60 273 OriginalGriff 173 Dave Kreskowiak 155 Richard Deeming 130 Sascha Lefèvre 110
 Dave Kreskowiak 2,276 OriginalGriff 1,624 Richard MacCutchan 1,530 CHill60 1,179 CPallini 1,122