Enumerations (for Customization)

This feature defines various enumeration types that allow developers to customize how numbers are rounded and displayed by selecting from predefined modes and styles.

Overview

The Enumerations for Customization in the SiticoneHumanizerFloat control include two key enums: one for specifying the rounding mode (RoundingModeEx) and another for defining the notation style (NotationStyle). These enumerations provide developers with a straightforward way to tailor the behavior of numeric formatting and representation. The RoundingModeEx enumeration allows for fine control over how numbers are rounded, while the NotationStyle enumeration determines the style in which numbers are formatted (e.g., Standard, Scientific, Engineering, Compact, Binary).


Key Points

Item
Description

RoundingModeEx

An enum that defines rounding behaviors, including HalfUp, HalfEven, Truncate, Ceiling, Floor, and SignificantDigits.

NotationStyle

An enum that specifies the formatting style, including Standard, Scientific, Engineering, Compact, and Binary.


Best Practices

Aspect
Recommendation

Select Appropriate Rounding Mode

Choose a rounding mode that aligns with your application's precision requirements; for example, use HalfUp for financial calculations and SignificantDigits for high-precision scientific computations.

Match Notation to Context

Use NotationStyle that best fits the data context (e.g., Scientific for extreme values, Compact for summarizing large numbers on dashboards).

Consistent Usage Across Application

Apply these enums consistently across different parts of your application to maintain a unified numeric presentation.


Common Pitfalls

Issue
Description
Resolution

Incorrect Rounding Mode Selection

Selecting a rounding mode that does not match the application's logic may result in unexpected numeric values.

Test each rounding mode with representative values to verify the outcome aligns with the business requirements.

Inconsistent NotationStyle Usage

Using different notation styles in various parts of the application may confuse users and lead to inconsistent data display.

Standardize the notation style across the application and document the rationale behind the chosen style.

Overlooking Edge Cases

Some numeric edge cases (e.g., very small or large numbers) may not be displayed as expected with the default enum settings.

Conduct thorough testing with a wide range of numeric inputs to ensure that the selected enum values provide the desired output.


Usage Scenarios

Scenario
Description

Financial Applications

Use RoundingModeEx.HalfUp with NotationStyle.Standard to ensure currency values are rounded and displayed in a conventional format.

Scientific Data Presentation

Apply RoundingModeEx.SignificantDigits along with NotationStyle.Scientific to accurately represent very large or small numbers.

Dashboard Reporting

Combine NotationStyle.Compact with RoundingModeEx.Truncate to create concise summaries of large data sets for dashboards.

Code Example: Configuring Rounding Mode and Notation Style

// Create an instance of the humanizer control
var humanizer = new SiticoneHumanizerFloat();

// Set the rounding mode to HalfUp for standard rounding
humanizer.RoundingMode = SiticoneHumanizerFloat.RoundingModeEx.HalfUp;

// Set the notation style to Standard
humanizer.Notation = SiticoneHumanizerFloat.NotationStyle.Standard;

// Assign a sample value
humanizer.Value = 12345.6789;

// Display the humanized value based on the selected enums
Console.WriteLine("Standard Format: " + humanizer.Humanized);

Code Example: Scientific Notation with Significant Digits

// Create an instance of the humanizer control
var scientificHumanizer = new SiticoneHumanizerFloat();

// Set the rounding mode to SignificantDigits for precise control
scientificHumanizer.RoundingMode = SiticoneHumanizerFloat.RoundingModeEx.SignificantDigits;

// Set the notation style to Scientific for exponential representation
scientificHumanizer.Notation = SiticoneHumanizerFloat.NotationStyle.Scientific;

// Assign a sample value
scientificHumanizer.Value = 0.00012345;

// Display the value in scientific notation
Console.WriteLine("Scientific Format: " + scientificHumanizer.Humanized);

Real Life Usage Scenarios

Scenario
Description

International Banking Systems

RoundingModeEx.HalfUp combined with NotationStyle.Standard ensures that all financial figures are rounded and displayed consistently for audit purposes.

Environmental Data Analysis

RoundingModeEx.SignificantDigits along with NotationStyle.Engineering can be used to represent sensor measurements accurately in engineering contexts.

Web-Based Analytics Dashboards

NotationStyle.Compact provides a simplified view of large numbers on dashboards, improving readability for end users.

Code Example: Dashboard Integration

// Example: Configuring a dashboard display using compact notation
var dashboardHumanizer = new SiticoneHumanizerFloat
{
    // Use Compact notation for a concise display of large numbers
    Notation = SiticoneHumanizerFloat.NotationStyle.Compact,
    // Set rounding mode to Truncate to simplify displayed values
    RoundingMode = SiticoneHumanizerFloat.RoundingModeEx.Truncate,
    MaxDecimalPlaces = 2,
    UseThousandsSeparator = true
};

dashboardHumanizer.Value = 987654321;
Console.WriteLine("Dashboard Format: " + dashboardHumanizer.Humanized);
// Expected output might be a compact form like "987.65M" depending on the custom suffix settings.

Troubleshooting Tips

Issue
Possible Cause
Suggested Action

Inaccurate Rounding

The selected RoundingMode may not suit the numeric data being processed.

Verify the output by testing with various numeric values and adjust the RoundingMode if necessary.

Confusing Notation Output

Using NotationStyle that doesn't match the context can lead to confusing or cluttered displays.

Experiment with different NotationStyle values and choose the one that provides the clearest representation.

Edge Case Handling

Extreme values may not display correctly if the enums are not tested thoroughly.

Test edge cases (very small or large numbers) and adjust the formatting properties or enums accordingly.


Review

Aspect
Review Notes

Customization Flexibility

The enumerations offer robust customization options that allow developers to fine-tune how numbers are displayed and rounded.

Ease of Implementation

The use of clear enum names and values makes it easy to integrate and understand the impact of each setting.

Potential Issues

Developers must carefully select the appropriate enum values to avoid unintended behavior, especially with edge cases.

Integration Consistency

Consistent use of these enums across the application enhances data presentation and overall user experience.


Summary

Summary Point
Description

Precise Rounding Control

RoundingModeEx enables developers to choose from multiple rounding strategies to meet specific precision requirements.

Versatile Display Options

NotationStyle offers various formats, such as Standard, Scientific, Engineering, Compact, and Binary, to suit different use cases.

Streamlined Customization

Enumerations simplify the configuration of numeric display settings, allowing for consistent and maintainable code.

Enhanced User Experience

Properly configured enums ensure that numerical data is presented clearly and accurately, improving user comprehension.


Additional Considerations

Consideration
Description

Documentation of Enum Choices

Clearly document which enum values are most appropriate for specific application scenarios to assist future developers.

Testing Across Data Sets

Test the numeric formatting across a variety of values to ensure that the chosen enum settings work well in all scenarios.

Future Enhancements

Consider adding additional enum values if new rounding strategies or notation styles are required by evolving application needs.

Code Example: Comprehensive Exception Handling with Enums

try
{
    // Example: Setting an unsupported enum value (this scenario is unlikely if using defined enums, but serves as a guard)
    humanizer.RoundingMode = (SiticoneHumanizerFloat.RoundingModeEx)999;
}
catch (ArgumentException ex)
{
    Console.WriteLine("Invalid rounding mode: " + ex.Message);
}

By leveraging the Enumerations (for Customization) in the SiticoneHumanizerFloat control, developers can fine-tune numeric formatting and rounding to suit a wide range of application scenarios. The clear and intuitive enum options simplify the integration process, ensuring that numbers are presented in a consistent, user-friendly manner across .NET WinForms applications.

Last updated