Solved

Round a string to two digits

Posted on 2016-11-16
12
31 Views
Last Modified: 2016-11-16
Hello,

How can I round a number to 2 digits

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

Expert Comment

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

Author Comment

by:RIAS
ID: 41889517
500.999
400.789
0
 
LVL 24

Expert Comment

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

501.00
400.80
0
 

Author Comment

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

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 24

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 24

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now