## Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
Solved

# Round a string to two digits

Posted on 2016-11-16
33 Views
Hello,

How can I round a number to 2 digits

Cheers
0
Question by:RIAS
• 6
• 5

LVL 28

Expert Comment

ID: 41889515
Sample example pls?
0

Author Comment

ID: 41889517
500.999
400.789
0

LVL 28

Expert Comment

ID: 41889519
Output should be below correct ?

501.00
400.80
0

Author Comment

ID: 41889522
400.789 to 400.79
0

LVL 28

Expert Comment

ID: 41889523
Try

``````Dim a As Decimal
a = 400.789

Dim b As Decimal
b = Math.Round(a, 2)

Console.WriteLine(b)
``````
0

Author Comment

ID: 41889527
maths.round is giving sqiggly red line
0

LVL 28

Expert Comment

ID: 41889528
Math.Round
0

Author Comment

ID: 41889530
yes, math.round red squggly
0

Author Comment

ID: 41889532
Severity      Code      Description      Project      File      Line      Suppression State
Error      BC30519      Overload resolution failed because no accessible 'Round' can be called without a narrowing conversion:
0

LVL 28

Assisted Solution

Pawan Kumar earned 250 total points
ID: 41889533
Math.Round

put same case I have given.. M and R should be capital , others small..
0

LVL 44

Accepted Solution

AndyAinscow earned 250 total points
ID: 41889543
Wierd, I made a comment in your last question and it was rejected because it rounded to 2 digits rather than truncated.
d.ToString("0.00")
0

Author Comment

ID: 41889571
Andy,

Sorry just overlooked it.

Cheers!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

#### 809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.