# Android QuestionAnyone can direct me to an integer formatting style: from 1250 to +1k

#### Hanz

##### Active Member
Hello,
Do we have a library which converts a number like 1250 into +1k? If none, any direction? Thanks!

#### aeric

##### Expert
Longtime User
Like this?
B4X:
``If number > 1000 Then Return "+1k" Else Return number``

#### Hanz

##### Active Member
Like this?
B4X:
``If number > 1000 Then Return "+1k" Else Return number``
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

#### MikeSW17

##### Active Member
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?

#### Hanz

##### Active Member
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.

#### pliroforikos

##### Active Member
You should continue the Select statements if you need larger numbers

B4X:
``````    Dim intA As Long = 4212357
Dim myInt As Long = intA

Dim sz As Int = 0
Do While intA > 0
intA = intA / 10
sz = sz + 1
Loop
Dim msg As String
Select sz
Case 1,2,3
Log(myInt)
Case 4,5,6
myInt = myInt / Power(10, 3)
msg = "+" & myInt & "K"
Log(msg)
Case 7,8,9
myInt = myInt /  Power(10, 6)
msg = "+" & myInt & "M"
Log(msg)
Case 10,11,12
myInt = myInt / Power(10, 9)
msg = "+" & myInt & "T"
Log(msg)
End Select``````

Last edited:

#### aeric

##### Expert
Longtime User
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
I just give you an example and you should code for yourself. It is not difficult.

#### Alexander Stolte

##### Expert
B4X:
``````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``````

#### William Lancee

##### Well-Known Member
Longtime User
Just for fun...

B4X:
``````    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``````

Replies
4
Views
482
Android Question NFC Questions
Replies
2
Views
806
Replies
21
Views
2K
Replies
3
Views
1K
Replies
3
Views
943