Results for “Numbers & numeric validation”
Small, practical examples. Search by task or narrow things down below.
Round a decimal with an explicit rule
Java: Construct BigDecimal from text to avoid importing a binary floating-point approximation.
Java✓ Tested
Round a halfway floating-point value
C: The C round function rounds halfway cases away from zero.
C✓ Tested
Round and format a decimal value
Round and format a decimal value in a complete Rust program using the standard library.
Rust✓ Tested
Round decimal amounts explicitly
Python: Build Decimal values from strings and choose a rounding rule explicitly.
Python✓ Tested
Round downward and upward independently
C: floor and ceil round toward negative and positive infinity respectively.
C✓ Tested
Round halfway floating-point values away from zero
C++: std::round has an explicit halfway rule different from truncation.
C++✓ Tested
Run cleanup after a caught exception
PowerShell: Use finally for cleanup that must occur after either success or failure.
PowerShell✓ Tested
Saturate arithmetic at the type boundary
Saturate arithmetic at the type boundary in a complete Rust program using the standard library.
Rust✓ Tested
Select the largest values without sorting everything
Python: Use heapq.nlargest when only a small prefix of the ranking is required.
Python✓ Tested
Subtract durations without underflow
Subtract durations without underflow in a complete Rust program using the standard library.
Rust✓ Tested
Track whether a form differs from its initial value
Track whether a form differs from its initial value with a small React component and explicit browser behavior.
React✓ Tested
Treat dynamic regex input as literal text
Java: Use Pattern.quote so metacharacters in a search term lose their special meaning.
Java✓ Tested