c# - Parsing pair of floats -


given string like: "0.123, 0.456" simplest way parse 2 float values 2 variables a , b?

i suggest:

  • split on comma (string.split)
  • trim (string.trim)
  • parse either float.parse or float.tryparse. (if want exception thrown if format incorrect, go parse. if want handle parsing failures part of normal control flow, use tryparse.)

if numbers going in format, explicitly specify cultureinfo.invariantculture. consider using decimal (or double) instead of float.


Comments

Popular posts from this blog

c++ - How to modify context menu of internet explorer using IDocHostUIHandler::ShowContextMenu? -

android - Spacing between the stars of a rating bar? -

c# - Getting "Internal .Net Framework Data Provider error 30" error when column has NULL value -