I have a gridview pulling from a SQL table and it contains varying dollar figures. They’re in thousands, millions or billions. I’m currently using {0:c0} but I’m interested in slimming this down so that I will show only three significant figures.
For instance, I’d like $3,411,216,512.07 to display as $3.41B; while $1,066,555.54 would be displayed as $1.07M.
Is there a simple way to do this in ASP.NET or do I need to break out the jQuery? Or alternatively, should I do it in C# OnRowDataBound?
You could convert the number to a string, grab the first four characters – assuming a pure number with no units, commas, etc – convert it back to a number, round it off, and then count the length of the original string to decide where to put the decimal point and what to label it with, be it B, M, K, etc. I’d suggest doing it server-side, I don’t see a point in doing it in the browser unless you want to make it interactive somehow.