parsing - C# Convert String Decimal to Int -


i have string "246246.246" i'd pass iconvertable interface, toint16, toint32, toin64. best way parse string decimal places integer?

this solution, there better solution?

string value = "34690.42724"; convert.toint64(convert.todouble(value)); 

to discounting rounding do:

convert.toint64(math.floor(convert.todouble(value))); 

if need round replace math.floor math.round.

edit: since mentioned in comment you'll rounding:

convert.toint64(math.round(convert.todouble(value))); 

if have worry localization/globalization @xls said should apply cultureinfo in conversions.

edit 2: alternative method using string function (not terribly elegant imo - maybe elegantized predicate function):

convert.toint64(value.substring(0, value.indexof('.') > 0 ? value.indexof('.') : value.length)); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -