How to show percentage sign on a specific column in datagridview

Viewed 20

The gm column on my excel file is showing percentage sign on all numbers. But when I show it to the datagridview, it turns into decimal. My gm is on string data type.

Here's my code

var gm = dt.Rows[i][27].ToString();

The Value of gm is based on the excel file gm column. I want it to show the percent sign on datagridview as well.

1 Answers

You can use the String.Format method to format youroutput, including custom text.

I don't know the exact structure of your data, so you will need to see what suits you best, but something like this:

var gm = String.Format(dt.Rows[1][27].ToString(), "##0.0 %");

This can also help you determine the best formatting: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings and https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

Related