?
Solved

vb.net currency display has four zeros instead of two

Posted on 2016-08-19
12
Medium Priority
?
42 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 2000 total points
ID: 41762376
have you tried:
DataGridView1.Columns("TEST").DefaultCellStyle.Format = "N2"

Open in new window

0
TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

801 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