Improve fraction formatting precision and output
Changes default precision from 1/32" to 1/16" for cleaner measurements and simplifies output by omitting unnecessary fraction components. - Change default precision from 32 to 16 - Return whole numbers without "-0/N" suffix when fraction rounds to zero - Update documentation to reflect new default precision This makes measurements more readable (e.g., "12" instead of "12-0/16") while maintaining sufficient precision for typical woodworking applications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace SawCut
|
||||
{
|
||||
@@ -11,9 +11,9 @@ namespace SawCut
|
||||
/// Converts a decimal measurement to a mixed fraction string representation.
|
||||
/// </summary>
|
||||
/// <param name="input">The decimal value to convert</param>
|
||||
/// <param name="precision">The denominator precision (default 32 for 1/32")</param>
|
||||
/// <param name="precision">The denominator precision (default 16 for 1/16")</param>
|
||||
/// <returns>A string in the format "whole-numerator/denominator"</returns>
|
||||
public static string ConvertToMixedFraction(decimal input, int precision = 32)
|
||||
public static string ConvertToMixedFraction(decimal input, int precision = 16)
|
||||
{
|
||||
// Get the whole number part
|
||||
int wholeNumber = (int)input;
|
||||
@@ -35,6 +35,12 @@ namespace SawCut
|
||||
numerator /= gcd;
|
||||
denominator /= gcd;
|
||||
|
||||
// If rounding wiped out the fraction → return whole number only
|
||||
if (numerator == 0)
|
||||
{
|
||||
return wholeNumber.ToString();
|
||||
}
|
||||
|
||||
return $"{wholeNumber}-{numerator}/{denominator}";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user