Solved

Converting string to currency

Posted on 2016-09-20
10
44 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 32

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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

14 Experts available now in Live!

Get 1:1 Help Now