|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
formatting questionHi 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! string.Format("{0:0.00}", value)
-- Show quoteRegards, Lloyd Dupont NovaMind development team NovaMind Software Mind Mapping Software <www.nova-mind.com> <param@community.nospam> wrote in message news:ugOHmhoBGHA.916@TK2MSFTNGP10.phx.gbl... > 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! > Anyway to do it in an easy way on an entire application?
Show quote "Lloyd Dupont" <net.galador@ld> wrote in message news:uhnHnYpBGHA.1676@TK2MSFTNGP09.phx.gbl... > string.Format("{0:0.00}", value) > > -- > Regards, > Lloyd Dupont > > NovaMind development team > NovaMind Software > Mind Mapping Software > <www.nova-mind.com> > <param@community.nospam> wrote in message > news:ugOHmhoBGHA.916@TK2MSFTNGP10.phx.gbl... >> 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! ""TerryFei"" <v-ter***@online.microsoft.com> wrote in message Show quote news:MKngIksBGHA.1236@TK2MSFTNGXA02.phx.gbl... > 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 > 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! ""TerryFei"" <v-ter***@online.microsoft.com> wrote in message Show quote news:Bn6a2d3BGHA.1236@TK2MSFTNGXA02.phx.gbl... > 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 > 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 That code worked for me. Why doesnt it work when I read a value from the db?
thanks! ""TerryFei"" <v-ter***@online.microsoft.com> wrote in message Show quote news:Udg$c0qCGHA.1424@TK2MSFTNGXA02.phx.gbl... > 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 |
|||||||||||||||||||||||