Solved

Converting string to currency

Posted on 2016-09-20
10
57 Views
Last Modified: 2016-09-22
Hello,
I am converting a datagridview value to currency

    If IsDBNull(sender.Rows(intRowIndex).Cells("Deposite").Value) = False Then
                str_Dep = CDbl(sender.Rows(intRowIndex).Cells("Deposite").Value)
            End If

Open in new window

but,the problem with the above code is that it converts
21.10 to 21.1 whereas the requirement is to convert it to 21.10
Any suggestions are welcome.

Cheers
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
  • 5
  • 4
10 Comments
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 100 total points
ID: 41806700
not sure if vb has the same string function this would be for c#
str_Dep = String.Format("{0:c}", CDbl(sender.Rows(intRowIndex).Cells("Deposite").Value))
0
 

Author Comment

by:RIAS
ID: 41806722
Working great p_davis but, it puts £ sign in front of the value.
Any suggestion ?
0
 
LVL 34

Accepted Solution

by:
it_saige earned 400 total points
ID: 41806812
It puts the £ sign in front of the string because c is the currency specifier, if you do not want the £ sign in front then you should use N or G instead:
Module Module1
	Sub Main()
		Dim value As Decimal = 21.2

		Console.WriteLine("{1,15}{0,5}{2,15}{0,5}{3,15}", " ", "Currency", "General", "Numeric")
		Console.WriteLine("{1,15}{0,5}{1,15}{0,5}{1,15}", " ", New String("_", 15))
		Console.WriteLine("{1,15:C}{0,5}{1,15:G}{0,5}{1,15:N}", " ", value)
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG
-saige-
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 22

Expert Comment

by:p_davis
ID: 41806990
i think saige is correct in suggesting the use of N... sorry, of course, i assumed somethingn i shouldn't have.
0
 

Author Comment

by:RIAS
ID: 41808515
Thanks Saige!!!
0
 
LVL 22

Expert Comment

by:p_davis
ID: 41808573
doesn't anyone believe in splitting points anymore?
0
 

Author Comment

by:RIAS
ID: 41808575
p_davis,
Sorry mate but,yours can be an assisted solution .Raising it.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 41808578
just appreciate a nod for the effort
0
 

Author Comment

by:RIAS
ID: 41808582
P_davis,

Was operating the solution from phone.Just accepted the solution in hurry.
Thanks once again.
0
 

Author Closing Comment

by:RIAS
ID: 41810204
Cheers!
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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 …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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