Shortens a given number to at most three digits with an SI unit after
- 987 => 10 h (hecto)
- 1234 => 1 k (kilo)
- 123456 => 123 k (kilo)
- 1234567 => 1 M (mega)
Full details on how to import
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
// Other repositories
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.richard-muvirimi:android-number-shortener:Tag'
}
val shorter = (123456).shorten()
//123.0 k
String shorter = NumberShort.INSTANCE.shorten(123456);
//123.0 k
All parameters are optional and with kotlin named parameters can be used just to edit the required parameters
round: Boolean // Whether to round off given number
suffix: String // String to add at the end of text after rounding off
precision: Int // The digits to keep after decimal comma
roundMode: RoundingMode // The mode to use for rounding up numbers
units: List<String> // List of units to use after shortening number
powers: List<Int> // Powers to use when shortening
You are welcome to send push requests (Just remember to add your name to the contributors list) or simply raise an issue
Copyright 2021 Tyganeutronics.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.