c# - Converting numbers as Facebook Like Counter -
this current code:
public static string formatnumber(int64 num) { if (num >= 100000) return formatnumber(num / 1000) + "thousand"; if (num >= 10000) { return (num / 1000d).tostring("0.#") + "thousand"; } return num.tostring("#,0"); }
question:
i want convert numbers facebook's counter.
examples:
190,000 => "190t"
244,555,232 => "190m 500t"
555,123,456,021 = "555b 123m"
is there possible way facebook counter?
here solution type of problem:
object[][] list = { new object[] {"b", 1000000000}, new object[] {"m", 1000000}, new object[] {"t", 1000} }; long num = 123412456255; // here should number of facebook likes string returned_string = ""; foreach (object[] in list) { if (num / convert.toint64(a[1]) >= 1) { returned_string += convert.toint64(num / convert.toint64(a[1])).tostring() + a[0] + " "; num -= convert.toint64(num / convert.toint64(a[1])) * convert.toint64(a[1]); } } console.writeline(returned_string);
Comments
Post a Comment