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

  • Home
  • SEARCH
  • 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 126949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:23:56+00:00 2026-05-11T05:23:56+00:00

In C# rounding a number is easy: Math.Round(1.23456, 4); // returns 1.2346 However, I

  • 0

In C# rounding a number is easy:

Math.Round(1.23456, 4); // returns 1.2346 

However, I want to round a number such that the fractional part of the number rounds to the closest fractional part of a predefined fraction (e.g. 1/8th) and I’m trying to find out if the .NET library already has this built in.

So, for example, if I want to round a decimal number to a whole eighth then I’d want to call something like:

Math.RoundFractional(1.9, 8); // and have this yield 1.875 Math.RoundFractional(1.95, 8); // and have this yield 2.0 

So the first param is the number that I want to round and the second param dictates the rounding fraction. So in this example, after rounding has taken place the figures following the decimal point can only be one of eight values: .000, .125, .250, .375, .500, .625, .750, .875

The Questions: Is this function built into .NET somewhere? If not, does anybody have a link to a resource that explains how to approach solving this problem?

  • 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. 2026-05-11T05:23:57+00:00Added an answer on May 11, 2026 at 5:23 am

    You could do this:

    Math.Round(n * 8) / 8.0 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

double a = 18.565 return Math.Round(a,2) ..returns 18.57. For every other number I tried
I'm running SQL that needs rounding up the value to the nearest whole number.
Well, basically I was using setprecision(3), but that is rounding up the last number,
According to Wikipedia when rounding a negative number, you round the absolute number. So
I want to round a value (double) to the next (allways round up) number.
In C# I want a function that rounds a given double to a given
There have been many threads started over the confusion in the way that Math.Round
I want to round a number to the nearest 'x'. I tried roundedNumber =
I would like to remove all trailing zeros without truncating or rounding the number
I was writing a function for rounding a number to two places. And I

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.