vb.net currency display has four zeros instead of two

Hello,
How to make it display two zeros:


 Public Sub Populate(ByVal Command As SqlCommand)
        'Accept command as string and fill the datatable with the result of sql query
        ' Test_Str = "Test"
        Dim dt = New DataTable
        Dim SQLdr As SqlDataReader
        Try




            SQLdr = Command.ExecuteReader()
            dt.BeginLoadData()
            dt.Load(SQLdr)
            dt.EndLoadData()
            Command.Connection.Close()
            Command.Dispose()
            Data_Table = dt

        Catch ex As Exception
                MessageBox.Show(ex.ToString)
        End Try

    End Sub
RIASAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
have you tried:
DataGridView1.Columns("TEST").DefaultCellStyle.Format = "N2"

Open in new window

0
 
Éric MoreauSenior .Net ConsultantCommented:
I don't see anything showing values. The 4 digits are surely coming from the database. The formatting has to be done on the client but it varies according to the control. So which control is showing your data?
0
 
RIASAuthor Commented:
Datagridview and radtextbox
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
RIASAuthor Commented:
Thanks it worked like a charm!
0
 
RIASAuthor Commented:
Any suggestion on

sender.Rows(intRowIndex).Cells("TotalPaid").value to display only two zeroes.

Cheers
0
 
Éric MoreauSenior .Net ConsultantCommented:
what is the issue? can't you set the column format like you did previously?
0
 
RIASAuthor Commented:
str_TotalPaid = sender.Rows(intRowIndex).Cells("TotalPaid").value

Sender is datagridview .

it worked to display the value in gridview correctly but when I extract the row it still shows with four values after decimal?
0
 
Éric MoreauSenior .Net ConsultantCommented:
how is str_TotalPaid declared? as a string?

str_TotalPaid = sender.Rows(intRowIndex).Cells("TotalPaid").value.ToString("N2")

Open in new window

0
 
RIASAuthor Commented:
Cheers Sir!
0
 
RIASAuthor Commented:
Hello Éric Moreau,
str_TotalPaid is a string
Got an error N2 to type integer is not valid.
0
 
Éric MoreauSenior .Net ConsultantCommented:
which error?  try this:
dim decTotal as decimal = convert.todecimal(sender.Rows(intRowIndex).Cells("TotalPaid").value)
str_TotalPaid = decTotal.ToString("N2")

Open in new window


The ToString  is  @ https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx
1
 
RIASAuthor Commented:
Thanks !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.