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
12
33 Views
Last Modified: 2017-01-24
Hello,

How can I round a number to 2 digits

Cheers
0
Comment
Question by:RIAS
  • 6
  • 5
12 Comments
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41889515
Sample example pls?
0
 

Author Comment

by:RIAS
ID: 41889517
500.999
400.789
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41889519
Output should be below correct ?

501.00
400.80
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:RIAS
ID: 41889522
400.789 to 400.79
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41889523
Try

Dim a As Decimal
        a = 400.789

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

        Console.WriteLine(b)

Open in new window

0
 

Author Comment

by:RIAS
ID: 41889527
maths.round is giving sqiggly red line
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41889528
Math.Round
0
 

Author Comment

by:RIAS
ID: 41889530
yes, math.round red squggly
0
 

Author Comment

by:RIAS
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

by:Pawan Kumar
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

by:
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

by:RIAS
ID: 41889571
Andy,

Sorry just overlooked it.

Cheers!
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

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.

Join & Ask a Question