PC Review


Reply
Thread Tools Rate Thread

How do I limit a value to 2 decimal places?

 
 
JamesL
Guest
Posts: n/a
 
      8th Jun 2005
Kind of a silly little one for me to be stumped on but:

I do some math on some values that represent money. The math may result in
several decimal places but since it is money I only want to display 2
decimal places on the screen and store 2 decimal places in my text file.
How do I limit the value to 2 decimal places.

This is usually pretty simple but I am stumped. Am I overlooking the
obvious on this one?

James Lysaght


 
Reply With Quote
 
 
 
 
Earl
Guest
Posts: n/a
 
      8th Jun 2005
I haven't had need to use this in CF, but in the full framework, you simply
do it like so:

SalePrice = Math.Round(yourDecimalValue, 2)

"JamesL" <(E-Mail Removed)> wrote in message
news:LZspe.741$(E-Mail Removed)...
> Kind of a silly little one for me to be stumped on but:
>
> I do some math on some values that represent money. The math may result
> in several decimal places but since it is money I only want to display 2
> decimal places on the screen and store 2 decimal places in my text file.
> How do I limit the value to 2 decimal places.
>
> This is usually pretty simple but I am stumped. Am I overlooking the
> obvious on this one?
>
> James Lysaght
>



 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      8th Jun 2005
Try this:

decimal d = 123.4567m;
d.ToString("0.00");

or

Math.Round(d, 2).ToString();

or

String.Format("{0:0.00}", d)


--
Sergey Bogdanov
http://www.sergeybogdanov.com


JamesL wrote:
> Kind of a silly little one for me to be stumped on but:
>
> I do some math on some values that represent money. The math may result in
> several decimal places but since it is money I only want to display 2
> decimal places on the screen and store 2 decimal places in my text file.
> How do I limit the value to 2 decimal places.
>
> This is usually pretty simple but I am stumped. Am I overlooking the
> obvious on this one?
>
> James Lysaght
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Limit decimal places without format statement Dirk Goldgar Microsoft Access Forms 1 4th Nov 2009 09:12 PM
Limit number of decimal places displayed dhstein Microsoft Access 1 7th Feb 2009 07:31 PM
How do I Limit decimal places in a string cell reference Ozinus Microsoft Excel Misc 3 29th Dec 2008 03:00 PM
Limit Decimal Places in Function =?Utf-8?B?dG1pbm4=?= Microsoft Access Forms 2 18th May 2005 06:21 PM
Limit decimal places with Excel automation =?Utf-8?B?YmF2amVhbg==?= Microsoft Access External Data 2 8th Feb 2005 12:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:29 AM.