-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to format settings trailing item
- Loading branch information
1 parent
33c87e7
commit 6fb8d03
Showing
4 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...eApp/src/androidJvmMain/kotlin/com/joaomanaia/game2048/core/util/StringUtil.androidJvm.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.joaomanaia.game2048.core.util | ||
|
||
import kotlin.text.format | ||
|
||
actual fun formatSettingTrailingNumber(value: Float): String { | ||
return "%.2f".format(value) | ||
} |
3 changes: 3 additions & 0 deletions
3
composeApp/src/commonMain/kotlin/com/joaomanaia/game2048/core/util/StringUtil.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.joaomanaia.game2048.core.util | ||
|
||
expect fun formatSettingTrailingNumber(value: Float): String |
This file contains 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
12 changes: 12 additions & 0 deletions
12
composeApp/src/wasmJsMain/kotlin/com/joaomanaia/game2048/core/util/StringUtil.wasmJs.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.joaomanaia.game2048.core.util | ||
|
||
actual fun formatSettingTrailingNumber(value: Float): String { | ||
val integerPart = value.toInt() | ||
val decimalPart = ((value - integerPart) * 100).toInt() | ||
|
||
return if (decimalPart < 10) { | ||
"$integerPart.0$decimalPart" | ||
} else { | ||
"$integerPart.$decimalPart" | ||
} | ||
} |