Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:04:49+00:00 2026-05-17T03:04:49+00:00

This i what I am trying to achieve: If a double has more than

  • 0

This i what I am trying to achieve:

If a double has more than 3 decimal places, I want to truncate any decimal places beyond the third. (do not round.)

Eg.: 12.878999 -> 12.878

If a double has less than 3 decimals, leave unchanged

Eg.:   125   -> 125
       89.24 -> 89.24

I came across this command:

double example = 12.34567;
double output = Math.Round(example, 3);

But I do not want to round. According to the command posted above,
12.34567 -> 12.346

I want to truncate the value so that it becomes: 12.345

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:04:50+00:00Added an answer on May 17, 2026 at 3:04 am

    Doubles don’t have decimal places – they’re not based on decimal digits to start with. You could get “the closest double to the current value when truncated to three decimal digits”, but it still wouldn’t be exactly the same. You’d be better off using decimal.

    Having said that, if it’s only the way that rounding happens that’s a problem, you can use Math.Truncate(value * 1000) / 1000; which may do what you want. (You don’t want rounding at all, by the sounds of it.) It’s still potentially “dodgy” though, as the result still won’t really just have three decimal places. If you did the same thing with a decimal value, however, it would work:

    decimal m = 12.878999m;
    m = Math.Truncate(m * 1000m) / 1000m;
    Console.WriteLine(m); // 12.878
    

    EDIT: As LBushkin pointed out, you should be clear between truncating for display purposes (which can usually be done in a format specifier) and truncating for further calculations (in which case the above should work).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to achieve this using parameter overloading using C++: Complex c(3.0, 4.0); double
This is what I am trying to achieve: if a property is set then
I am trying to achieve something like this. The Expandable List consists of the
I'm trying to achieve what this guy here is doing, only in PHP or
I am trying to achieve this effect where a photo gets a repeating pattern
I'm trying to achieve URLs like this in Rails: http://localhost/posts/1234/post-slug-name with both ID and
I am trying to achieve this using Expression Blend 3. I need that every
this is the scenario i'm trying to achieve: a sound stored on the same
I'm trying to achieve something similar to jQuery Glow or this fiddle . Specifically
I am trying to achieve exactly something like this - a text view on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.