Skip to content

AnnaBaeTofuMom/KWNumberFormatter

Repository files navigation

KWNumberFormatter

CI Status Version License Platform

Introduction

To run the example project, clone the repo, and run pod install from the Example directory first.

KWNumberFormatter is a library that facilitates easy handling of the decimal part of Double, Float, and Decimal types. It allows you to limit the number of decimal places or fill the decimal part with zeros. For the integer part, you can insert or remove commas as needed.

Requirements

Installation

KWNumberFormatter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'KWNumberFormatter'

How to use

  1. import KWNumberFormatter
  2. make formatter instance by initializing KWFormatter
  3. change shape of number using function format()
import KWNumberFormatter

let formatter = KWFormatter()
let decimal: Decimal = 23423524.12334
let decStr = formatter.format(number: decimal, comma: true, roundMode: .ceil, fillZero: true, maxDigit: 9) //  returns "23,423,524.123340000"

About KWRoundMode

The RoundMode in KWNumberFormatter is used for the decimal part of the number. For example, if you choose the "ceil" mode and specify the maximum number of decimal digits, the remaining decimal digits will be removed and the last digit will be rounded up. The "round" mode works like 'awayFromZero' of 'FloatingPointRoundingRule'

Author

anna.bae, [email protected]

License

KWNumberFormatter is available under the MIT license. See the LICENSE file for more info.

About

Handle decimal part of number with KWNumberFormatter.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published