no, something like dim s as string = some_library(1250) and returns +1K even the number is 1200, 1300, 1500, and so on... and if it is 2500 the return value is +2k
The question is too vague, so has too many (probably incorrect) answers.
Do you simply want to truncate the least significant 3(?) digits? or round to nearest thousand?, or what?
The question is too vague, so has too many (probably incorrect) answers.
Do you simply want to truncate the least significant 3(?) digits? or round to nearest thousand?, or what?
okay, I am learning the badger class by erel. But it can contain only about 2 or 3 numbers. Beyond it, you can no longer see the other digits. I'm thinking, instead of showing the entire numbers such as 1000 or 10000, I can show +1k only or +9k.
no, something like dim s as string = some_library(1250) and returns +1K even the number is 1200, 1300, 1500, and so on... and if it is 2500 the return value is +2k
Public Sub ShortenNumber(Value As Int) As String
'https://en.wikipedia.org/wiki/Unit_prefix
Dim unitprefix As String
If Value >= 1000000 Then
Value = Value / 1000000
unitprefix ="M"
Else If Value >= 1000 Then
Value = Value / 1000
unitprefix = "k"
Else
Return Value
End If
Return NumberFormat(Value ,1,0) & unitprefix
End Sub
Dim origValue As Double = 2023123.345
Dim logX As Int = Floor(Logarithm(origValue, 10))
Dim result As String
Select logX
Case 0, 1, 2: result = Round(origValue)
Case 3, 4, 5: result = Round(origValue / 1000) & "K"
Case 6, 7, 8: result = Round(origValue / 1000000) & "M"
Case 9, 10, 11: result = Round(origValue / 1000000000) & "B"
End Select
Log(result) '2M