Created
November 23, 2021 06:17
-
-
Save EmmanuelGuther/fe84750c9b2b748a134929bbbe556e8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test if number have not numFractionDigits ex: (40.12345).roundTo(7) cant get the last 7 because have 5 | |
private fun Double.maxDecimals(numFractionDigits: Int) = try { | |
val factor = 10.0.pow(numFractionDigits.toDouble()) | |
(this * factor).roundToInt() / factor | |
} catch (e: Exception) { | |
e.localizedMessage?.toString()?.let { Log.e("Double.maxDecimals", it) } | |
this | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment