As you can see in the attached file. (the answer to a big multiplication).
instead of getting that amount of numbers after the "dot" I would like to just get something like this: 6.5916E35 just 3 to 4 numbers but also showing E35
is there a way of doing it?
I already tried limiting the amount of number the edittext can hold. but by doing so it also cut the answer. for example if I limit the amount of number of the edittext to 5 the answer would be: 6.5916 eliminating E35 and that is an incorrect answer.
Dim MyString As String="6.59163647839E35"
Dim strVar() As String=Regex.Split("E",MyString)
Msgbox("My result is = " & NumberFormat(strVar(0),1,4) & "E" & strVar(1),"") 'displays: 6.59163E35
Dim MyString As String="6.59163647839E35"
Dim strVar() As String=Regex.Split("E",MyString)
Msgbox("My result is = " & NumberFormat(strVar(0),1,4) & "E" & strVar(1),"") 'displays: 6.59163E35
The calculation will yield a value (Myresult) before it is plugged into the text box. You can then have this code:
B4X:
Dim MyResult As String
Dim strVar() As String=Regex.Split("E",MyResult)
EditText1.text=NumberFormat(strVar(0),1,4) & "E" & strVar(1) 'The text box will show the format: 9999E99
The calculation will yield a value (Myresult) before it is plugged into the text box. You can then have this code:
B4X:
Dim MyResult As String
Dim strVar() As String=Regex.Split("E",MyResult)
EditText1.text=NumberFormat(strVar(0),1,4) & "E" & strVar(1) 'The text box will show the format: 9999E99
Sub Globals
Dim ans As String
Dim strVar() As String=Regex.Split("E",ans)
End Sub
Sub Button12_Click 'equal button
If Sign = "*" Then
ans = one * two
EditText1.text = NumberFormat(strVar(0),1,4) & "E" & strVar(1)
Stat = 1
End If
You can not do the Regex in Globals, it has no value. It must be used after you have an answer that needs corrected only. Your Button12_Click sub should look something like this:
B4X:
Sub Button12_Click
Dim MyString As String
MyString = "6.59163647839E35" 'This is where you must assign your answer to MyString, this is just a sample
If MyString.Contains("E") Then
Dim strVar() As String = Regex.Split("E", MyString)
Log("My result is = " & NumberFormat(strVar(0), 1, 4) & "E" & strVar(1))
Else
Log("My result is = " & NumberFormat(MyString, 1, 4))
End If
End Sub
You can not do the Regex in Globals, it has no value. It must be used after you have an answer that needs corrected only. Your Button12_Click sub should look something like this:
B4X:
Sub Button12_Click
Dim MyString As String
MyString = "6.59163647839E35" 'This is where you must assign your answer to MyString, this is just a sample
If MyString.Contains("E") Then
Dim strVar() As String = Regex.Split("E", MyString)
Log("My result is = " & NumberFormat(strVar(0),1,4) & "E" & strVar(1))
Else
Log("My result is = " & MyString)
End If
End Sub