Skip to content

Normalization & String Literal Expressibility#13

Open
adam-rocska wants to merge 2 commits into
mgriebling:mainfrom
adam-rocska:main
Open

Normalization & String Literal Expressibility#13
adam-rocska wants to merge 2 commits into
mgriebling:mainfrom
adam-rocska:main

Conversation

@adam-rocska

@adam-rocska adam-rocska commented Jul 31, 2025

Copy link
Copy Markdown

BigDecimal is now ExpressibleByStringLiteral

This empowers Swift programmers to utilize the
following syntax sugar:

let values: [BigDecimal] = [
  "123.456",
  "123.456",
  "123.456",
  "123.456",
  "123.456",
  "123.456",
  "123.456"
]

This empowers Swift programmers to utilize the
following syntax sugar:
```swift
let values: [BigDecimal] = [
  "123.456",
  "123.456",
  "123.456",
  "123.456",
  "123.456",
  "123.456",
  "123.456"
]
````
@adam-rocska

Copy link
Copy Markdown
Author

The tests pass, and the feature works. Let me know if there are any typos or unwanted details that might have slipped through.

I’m visually impaired, and VoiceOver can only take you so far.

Initializes a normalized copy of a `BigDecimal`,
stripping trailing zeros when the exponent is
negative.

Useful when you end up with a BigDecimal filled
with insignificant zeros.

Example occurrence
------------------

Context: Unit of Measure conversions & dimensions
A conversion chain of
```
inch -> feet -> miles -> kilometers -> picometers
-> astronomical units -> inch
```
works like magic using BigDecimal, but the end
result when yielded as a string, contains the
zeros accumulated along the journey.

This contribution aims to provide a solution for
such cases.
@adam-rocska

Copy link
Copy Markdown
Author

Added a BigDecimal(normalize: BigDecimal) API
Initializes a normalized copy of a BigDecimal,
stripping trailing zeros when the exponent is
negative.

Useful when you end up with a BigDecimal filled
with insignificant zeros.

Example occurrence

Context: Unit of Measure conversions & dimensions
A conversion chain of

inch -> feet -> miles -> kilometers -> picometers
-> astronomical units -> inch

works like magic using BigDecimal, but the end
result when yielded as a string, contains the
zeros accumulated along the journey.

This contribution aims to provide a solution for
such cases.

@adam-rocska adam-rocska changed the title BigDecimal is now ExpressibleByStringLiteral Normalization & String Literal Expressibility Jul 31, 2025
adam-rocska added a commit to adam-rocska/BigDecimal that referenced this pull request Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant