Solved

vb.net currency display has four zeros instead of two

Posted on 2016-08-19
12
39 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 70

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 70

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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 

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 70

Expert Comment

by:Éric Moreau
ID: 41765372
what is the issue? can't you set the column format like you did previously?
0
 

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 70

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 70

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 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