Skip to content

Instantly share code, notes, and snippets.

@taurenshaman
Last active September 1, 2018 04:44
Show Gist options
  • Save taurenshaman/f3c7fc51406d199890a3176e3e37a61b to your computer and use it in GitHub Desktop.
Save taurenshaman/f3c7fc51406d199890a3176e3e37a61b to your computer and use it in GitHub Desktop.
compare two numbers stored as strings without converting them to double/int/float
// https://stackoverflow.com/a/14468767
var numbers = new string[] { "100" ,"200", "100.1" , "200.1" };
int N = 100;
var max = numbers.Select(n => n.Split('.'))
.OrderByDescending(p => p[0].PadLeft(N,'0'))
.ThenByDescending(p => p.Length > 1 ? p[1].PadRight(N, '0') : "")
.Select(p => p.Length > 1 ? p[0] + "." + p[1] : p[0])
.First();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment