Solved

Round a string to two digits

Posted on 2016-11-16
12
25 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 18

Expert Comment

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

Author Comment

by:RIAS
ID: 41889517
500.999
400.789
0
 
LVL 18

Expert Comment

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

Expert Comment

by:Pawan Kumar Khowal
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 18

Expert Comment

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

Assisted Solution

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 41
Windows Service to Receive TCP Packets 4 48
Showdialog 8 21
Open a word document 23 19
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…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

11 Experts available now in Live!

Get 1:1 Help Now