Solved

vb.net currency display has four zeros instead of two

Posted on 2016-08-19
12
33 Views
Last Modified: 2016-08-23
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
0
Comment
Question by:RIAS
  • 7
  • 5
12 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41762352
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
 

Author Comment

by:RIAS
ID: 41762353
Datagridview and radtextbox
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 41762376
have you tried:
DataGridView1.Columns("TEST").DefaultCellStyle.Format = "N2"

Open in new window

0
 

Author Closing Comment

by:RIAS
ID: 41762429
Thanks it worked like a charm!
0
 

Author Comment

by:RIAS
ID: 41765335
Any suggestion on

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

Cheers
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41765372
what is the issue? can't you set the column format like you did previously?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:RIAS
ID: 41765379
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41765634
how is str_TotalPaid declared? as a string?

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

Open in new window

0
 

Author Comment

by:RIAS
ID: 41765676
Cheers Sir!
0
 

Author Comment

by:RIAS
ID: 41766493
Hello Éric Moreau,
str_TotalPaid is a string
Got an error N2 to type integer is not valid.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41766657
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
 

Author Comment

by:RIAS
ID: 41766663
Thanks !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now