Solved

Converting string to currency

Posted on 2016-09-20
10
48 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
  • 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 33

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

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.

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 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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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