c# - Single.TryParse always failing -
i've been looking @ calculator friend, , we're having difficulties single.tryparse method.
according msdn, following code should work:
float j; if (single.tryparse("1.5", out j)) console.writeline(j); else console.writeline("string not parsed.");
but outputs string not parsed. know why might case?
this using visual studio 2015, community edition - believe use .net 4.6?
other code i've tried:
string value = "1.5"; float number; numberstyles style = system.globalization.numberstyles.allowdecimalpoint; cultureinfo culture = system.globalization.cultureinfo.createspecificculture("en-gb"); if (single.tryparse(value, style, culture, out number)) console.writeline(number); else console.writeline("error parsing number");