Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2005

Tip: Looking for answers? Try searching our database.

formatting question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
param@community.nospam - 21 Dec 2005 23:43 GMT
Hi all, I store all my currency values in a Decimal type. The problem is
that when I render it as price.toString("n") it sticks in 4 decimal places.
I only need 2. How can I configure the application to only do 2 decimal
places?

TIA!
Lloyd Dupont - 22 Dec 2005 01:22 GMT
string.Format("{0:0.00}", value)

Signature

Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>

> Hi all, I store all my currency values in a Decimal type. The problem is
> that when I render it as price.toString("n") it sticks in 4 decimal
> places. I only need 2. How can I configure the application to only do 2
> decimal places?
>
> TIA!
param@community.nospam - 22 Dec 2005 05:07 GMT
Anyway to do it in an easy way on an entire application?

> string.Format("{0:0.00}", value)
>
[quoted text clipped - 4 lines]
>>
>> TIA!
"TerryFei" - 22 Dec 2005 07:26 GMT
Hi,
Welcome to MSDN Newsgroup!

The default decimal places are decided on the setting of "Regional Options"
in machine. You could set the number of decimal places manually as follows,
1.    Open "Control Panel"
2.    Choose "Regional and Language Options"
3.    Under "Regional Options" tab, click "Customize" button
4.    Set the value of "No. of digits after decimal" to yours

We also could use (string.Format("{0:0.00}", value)) to force a specified
format in program.

I hope the above information is helpful for you. If you have any questions,
please feel free to join the community and we are here to support you at
your convenience. Thanks again and Merry Christmas!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
param@community.nospam - 22 Dec 2005 19:12 GMT
Terry, for currency my Regional Settings are set to 2 decimal places. The
problem is when I cast a Decimal type to string using dec.toString("n")...

TIA!

> Hi,
> Welcome to MSDN Newsgroup!
[quoted text clipped - 21 lines]
> Microsoft Community Support
> Get Secure! www.microsoft.com/security
"TerryFei" - 23 Dec 2005 04:15 GMT
Hi,
Thanks for your feedback!

In this scenario, I want to confirm what's the setting of "Number" tab in
"Customize Regional Options". On my side, when I set "No. of digits after
decimal" value to ours, the numbers of decimal (string.toString("n")) will
adjust to the relevant setting.
If the problem is still experienced, I hope you could send me a simplified
sample so that I could repro this problem on my side and get closer to this
issue. Thanks for your understanding!

Merry Christmas!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
param@community.nospam - 24 Dec 2005 22:14 GMT
I checked the server and the No. of digits after decimal is 2 for me. Here
is my code:-

Dim val as Decimal = Cdec(dr("val1")) ' read from datareader
input1.value = val.toString("n")

Thanks & Have a Merry Xmas!

> Hi,
> Thanks for your feedback!
[quoted text clipped - 15 lines]
> Microsoft Community Support
> Get Secure! www.microsoft.com/security
"TerryFei" - 27 Dec 2005 06:16 GMT
Hi,
Thanks for your response!

The following code works well on my side, I suggest you could test it on
your machine.

       Dim val As Decimal = 10.111111
       Dim str As String
       str = val.ToString("n")
       MsgBox(str)

These tests will help us get closer to resolving your issue, so I
appreciate your time in performing them. Let me know the results at your
earliest convenience. If you have any questions or concerns, please let me
know. I am standing by to help you.
Merry Christmas!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
param@community.nospam - 29 Dec 2005 17:31 GMT
That code worked for me. Why doesnt it work when I read a value from the db?

thanks!

> Hi,
> Thanks for your response!
[quoted text clipped - 18 lines]
> Microsoft Community Support
> Get Secure! www.microsoft.com/security
"TerryFei" - 30 Dec 2005 02:40 GMT
Hi,
Thanks for your feedback!

Based on my experience, this issue may be related to your detailed context.
I suggest you check the format of value in database. As a workaround, you
could try to use code (string.Format("{0:0.00}", value) ) to resolve it.
If you have any questions, please feel free to let me know. Happy New Year!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.