CodeSOD: Rounding Percentages

This post was originally published on this site

The Daily WTF

These days, every language in wide use has support for unicode characters, at least in strings. This is excellent, because it means we can program like the kids these days, with loads of emojis. I’m cool. This is what cool looks like: 😎.

You know what else is cool? National ID systems. One particular European country has rolled out a new software backend for their national ID system. Dimitry has the privilege to see the code. This is how they show the user how complete something is, as a percentage:

private static string GetPercentageRounds(double percentage) { if (percentage == 0) return “⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪”; if (percentage > 0.0 && percentage <= 0.1) return “🔵⚪⚪⚪⚪⚪⚪⚪⚪⚪”; if (percentage > 0.1 && percentage <= 0.2) return “🔵🔵⚪⚪⚪⚪⚪⚪⚪⚪”; if (percentage > 0.2 && percentage <= 0.3) return “🔵🔵🔵⚪⚪⚪⚪⚪⚪⚪”; if (percentage > 0.3 && percentage <= 0.4) return “🔵🔵🔵🔵⚪⚪⚪⚪⚪⚪”; if (percentage > 0.4 && percentage <= 0.5)

To read the full article click on the 'post' link at the top.