944,051 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 131646
  • VB.NET RSS
Jul 28th, 2007
0

Two Decimal Places

Expand Post »
Hi,
Could you please show me how to get
1.9
to show with two decimal places (1.90)


you can use
VB.NET Syntax (Toggle Plain Text)
  1. Math.Round(1.99999999, 2)
if you want to bring the decimal places down to two
but how do you increase from zero or one decimal place up to two?


Thanks
Peter
Similar Threads
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006
Jul 29th, 2007
0

Re: Two Decimal Places

Hi,

Check this :

TextBox1.Text = Format(1.9, "0.00")
 
TextBox2.Text = Format(22, "0.00")

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Jul 29th, 2007
0

Re: Two Decimal Places

Thanks QVeen72,
It work perfectly.

I've only ever used Format with Dates beform and it never occured to used it with numerics


Thanks
Peter
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006
May 10th, 2009
0

Re: Two Decimal Places

Click to Expand / Collapse  Quote originally posted by ptaylor965 ...
Hi,
Could you please show me how to get
1.9
to show with two decimal places (1.90)


you can use
VB.NET Syntax (Toggle Plain Text)
  1. Math.Round(1.99999999, 2)
if you want to bring the decimal places down to two
but how do you increase from zero or one decimal place up to two?


Thanks
Peter
You can also use; assuming the variable is named dblResult...
VB.NET Syntax (Toggle Plain Text)
  1. CStr(dblResult.ToString("#,##0.00"))
It worked for me and it does round up/down as needed.
Last edited by eGadgetGuy; May 10th, 2009 at 7:53 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eGadgetGuy is offline Offline
1 posts
since May 2009
Jan 19th, 2010
2

vb.net - two decimal places (without currency symbol)

If you store your number in a variable of decimal type, you can convert into a string with two decimal places (including .00) this way:

Dim dAmount as Decimal
Dim strFormattedAmount as String

strFormattedAmount= dAmount.ToString("N2")



Click to Expand / Collapse  Quote originally posted by ptaylor965 ...
Hi,
Could you please show me how to get
1.9
to show with two decimal places (1.90)


you can use
VB.NET Syntax (Toggle Plain Text)
  1. Math.Round(1.99999999, 2)
if you want to bring the decimal places down to two
but how do you increase from zero or one decimal place up to two?


Thanks
Peter
Reputation Points: 11
Solved Threads: 0
Newbie Poster
ssommaro is offline Offline
2 posts
since Jan 2010
May 7th, 2010
0
Re: Two Decimal Places
Click to Expand / Collapse  Quote originally posted by ssommaro ...
If you store your number in a variable of decimal type, you can convert into a string with two decimal places (including .00) this way:

Dim dAmount as Decimal
Dim strFormattedAmount as String

strFormattedAmount= dAmount.ToString("N2")
Try this:
String.Format("{0:f2}", CType("10.22222222", Decimal))
http://vbdotnettutorial.blogspot.com...al-points.html
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbdotnettut is offline Offline
2 posts
since May 2010
May 8th, 2010
0
Re: Two Decimal Places
Please do not resurrect old threads. If you want to ask question, start your own thread. Please read the rules before posting again - http://www.daniweb.com/forums/thread78223.html and rules.
Last edited by Nick Evan; Feb 4th, 2011 at 11:56 am. Reason: Removed "closing" remark
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in VB.NET Forum Timeline: Are these references required for VS 2008 users as well?
Next Thread in VB.NET Forum Timeline: Crystal Report parameter





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC