Avatar of techques
techques
 asked on

How to strip off numbers after the first decimal place?

Hi

Here are the decimal:
1600.15
200.46
12.89

How can I strip off the 2nd decimal place to make those decimal to be:
1600.1
200.4
12.8

I have the following code to return bool if it is more than one decimal place.

But, how can I strip off and return the one decimal place number in VC#?
public bool CheckDecimal(string number)
        {
            bool isValid = true;
            if (number.Substring(number.Length - 1, 1) != ".")
            {
                isValid = false;
            }
}

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
philipjonathan

8/22/2022 - Mon
rgn2121

I think this link should provide exactly what you need...

Credit to the original poster...
rgn2121

rgn2121

I just realized that you are the previous asker...You accepted the solution in the other thread and the question seems nearly identical....was there an issue with what was posted and selected as the answer in the other thread?
Your help has saved me hundreds of hours of internet surfing.
fblack61
cdaly33

Math.Round(123,1)
ASKER CERTIFIED SOLUTION
philipjonathan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
techques

ASKER
may i ask what does if (pos < 0) mean?
philipjonathan

That if statement is to check if the '.' character was not found in number, which means the number has no decimal points at all.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.