formatting question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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
 
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,
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
 
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 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
 
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
 
Back
Top