RishiKumar2210
Active Member
I Need to Convert number 1709165749 into 170,91,65,749.00 in B4A. is this possible?
Last edited:
I have problems in these format.Search Results
www.b4x.com
[B4X] Lakh format number
Attached is a demo and code to convert numbers to Lakh format. UPDATE: Formatting using the B4XFormatter library. Ref: https://www.b4x.com/android/forum/threads/convert-number-into-lakhs-with-decimal.149419/ NumberFormatLakh(250000, 1, 2) 'Converts the specified number to a string in...www.b4x.com
Yeah. I am Sure. this is not a valid solution for my problem.As already suggested by Erel, are you sure this doesn't solve your problem ?
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).Hi @RishiKumar2210 , if you want Indian format, check below,
[B4X] Format 10,000 (Ten Thousand) to Lakh
B4J 2.80+ Sub FormatLakh(number As Double, decimals As Int) As String Dim dd As Int, ss As String Dim mm As Long = Abs(number) Dim nn As Long = mm / 1000 Dim dc As Double = (mm Mod 1000) + Abs(number) - mm Dim lakh As String = NumberFormat2(dc, 1, decimals, decimals, False)...www.b4x.com
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.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).
2. I need format like this(190,91,79,610.00)
I Need to Convert number 1709165749 into 170,91,65,749.00 in B4A. is this possible?
Good question, I investigated.why is it not 1,70,91,65,749.00 ?
' 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
' 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
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.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/
Not sure what is the correct/common use in different parts of India.And every group of two digits after the first 3 is correct?
I Need 3rd Format.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,000,000,000,000
- 10,00,00,00,00,000
- 1,00,000,00,00,000
The code in #13 is not giving the enough result. It is not working for decimal numbers like(170,29,78.918.93).@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.