Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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?
Avatar of RIAS

ASKER

Datagridview and radtextbox
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Thanks it worked like a charm!
Avatar of RIAS

ASKER

Any suggestion on

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

Cheers
what is the issue? can't you set the column format like you did previously?
Avatar of RIAS

ASKER

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?
how is str_TotalPaid declared? as a string?

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

Open in new window

Avatar of RIAS

ASKER

Cheers Sir!
Avatar of RIAS

ASKER

Hello Éric Moreau,
str_TotalPaid is a string
Got an error N2 to type integer is not valid.
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
Avatar of RIAS

ASKER

Thanks !