Android Question Number into Lakh Format

Status
Not open for further replies.

MarcoRome

Expert
Licensed User
Longtime User
As already suggested by Erel, are you sure this doesn't solve your problem ?
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Hi @RishiKumar2210 , if you want Indian format, check below,
 
Upvote 0

RishiKumar2210

Active Member
Hi @RishiKumar2210 , if you want Indian format, check below,
Yeah. I already seen this But this is not sufficient for me. Because if values comes in crores like 120 or 70 crores, I need format like this(120,20,50,000.00, 70,20,50,000).
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
But this is not sufficient for me. Because if values comes in crores like 120 or 70 crores, I need format like this(120,20,50,000.00, 70,20,50,000).

How is the formatter to know that you'd like the first example expressed to two decimal places, and the second example to zero decimal places?
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Yeah. I already seen this But this is not sufficient for me. Because if values comes in crores like 120 or 70 crores, I need format like this(120,20,50,000.00, 70,20,50,000).
Since the example shows the code, so you can modify it to suit your need and if happy with it, then share it in the Forum for rest of the members.
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@emexes
why is it not 1,70,91,65,749.00 ?
Good question, I investigated.

At the risk of stepping out my comfort zone (apologies in advance to those who really know!),
The following seems to suggest that it is more complicated than every group of two digits after the first 3.
I presume that the 2 decimal digits are an addition for fractional amounts.

sanskrit.png
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
And applying that logic

B4X:
'    Dim pattern As String = "0,00,000,00,000,00,000,00,000,00,00,000.00"
'    Dim number As Long =  170916574900
'    Log(applyPattern(pattern, number))        170,91,65,749.00

Private Sub applyPattern(pattern As String, number As Long) As String
    Dim s As String = number
    Dim result As String
    Dim index As Int = pattern.length - 1
    For i = s.Length - 1 To 0 Step -1
        Dim digit As String = s.CharAt(i)
        Dim c As String = pattern.charAt(index)
        If c <> "0" Then
            result = c & result
            index = index - 1
        End If
        result = digit & result
        index = index - 1
    Next
    Return result
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
As inspired by @emexes, here is an improved version that accommodates
negative numbers and sub-one decimals.

B4X:
'    Dim pattern As String = "1,00,000,00,000,00,000,00,000,00,00,000.00"
'    Log(applyPattern(pattern, 170916574900))    '    170,91,65,749.00
'    Log(applyPattern(pattern, -100000))            '    -1,000.00
'    Log(applyPattern(pattern, 3))                '    0.03
'    Log(applyPattern(pattern, -3))                '    -0.03

Private Sub applyPattern(pattern As String, number As Long) As String
    Dim s As String = number
    Dim prefix As String
    If s.StartsWith("-") Then
        prefix = "-"
        s = s.SubString(1)
    End If
    If s.Length < 3 Then s = (1000 + Abs(number)).As(String).substring(1)
    Dim result As String
    Dim index As Int = pattern.length - 1
    For i = s.Length - 1 To 0 Step -1
        Dim digit As String = s.CharAt(i)
        Dim c As String = pattern.charAt(index)
        If c <> "0" Then
            result = c & result
            index = index - 1
        End If
        result = digit & result
        index = index - 1
    Next
    Return prefix & result
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Thank you @aeric

So since there is name for 100 Crore and a 100 Arab, a comma is customary?
And therefore the pattern is "00,00,00,00,00,000.00"

1 Lakh = 100 Thousand
1 Crore = 100 Lakh
1 Arab = 100 Crore
1 Kharab = 100 Arab

And every group of two digits after the first 3 is correct?
 
Upvote 0

RishiKumar2210

Active Member
why is it not 1,90,91,79,610.00 ?

and on a related note:



why is it not 1,70,91,65,749.00 ?



"In the Indian place-value system, we insert a comma after three digits then after every two-digit"

https://www.cuemath.com/questions/p...ystem-and-write-the-number-name-of-27597-219/
Because If the format like this(170,91,65,749.00) It is easy to read and understand for me ( As an Indian) within a second and if the pattern like this(1,70,91,65,749.00), it seems quite difficult for understand.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
And every group of two digits after the first 3 is correct?
Not sure what is the correct/common use in different parts of India.

e.g. 10 Kharab or 1 Lakh Crore or 1 Trillion (12 zeros) is?
  1. 1,000,000,000,000
  2. 10,00,00,00,00,000
  3. 1,00,000,00,00,000
 
Last edited:
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@RishiKumar2210

Without that, I was just guessing. Never a good idea. In this case I came up with the right answer for the wrong reason.
The code in #13 will get you that answer.

In case it isn't clear, I dealt with the the 2 decimal places by multiplying the number by 100 before applying the pattern.
 
Upvote 0

RishiKumar2210

Active Member
@RishiKumar2210

Without that, I was just guessing. Never a good idea. In this case I came up with the right answer for the wrong reason.
The code in #13 will get you that answer.

In case it isn't clear, I dealt with the the 2 decimal places by multiplying the number by 100 before applying the pattern.
The code in #13 is not giving the enough result. It is not working for decimal numbers like(170,29,78.918.93).
 
Upvote 0
Status
Not open for further replies.
Top