# Display Scientific Notation

#### metrick

##### Active Member
How can I convert calculated result to display in scientific notation if result is > 999999? Numberformat, NumberFormat2 have not option to display scientific notation. Could not find any function to do this. Thanks.

#### Erel

##### B4X founder
Staff member
The scientific notation is applied automatically when the number is larger than 10,000,000.
Try this code:
B4X:
``````For i = 1 To 20
Log(Power(10, i))
Next``````

#### ValDog

##### Active Member
Here's a routine I developed to convert to scientific notation:

Sub Val2Sci(Value As Double, DecPlaces As Int) As String
Dim bNeg As Boolean
Dim dTemp As Double
Dim i As Int
Dim sTemp As String

If Value < 0 Then
Value = Value * -1
bNeg = True
End If

If Value > 1 Then
'divide by 10 until Value < 10; count # of times it was divided to get exponent
i = 0
Do Until Value < 10
Value = Value / 10
i = i + 1
Loop
sTemp = NumberFormat2(Value,1,DecPlaces,DecPlaces, False)
If i < 10 Then
sTemp = sTemp & "E+0" & i
Else
sTemp = sTemp & "E+" & i
End If
Else If Value < 1 Then
'multiply by 10 until Value > 1; count # of times it was multiplied to get the
' negative exponent
i = 0
Do Until Value > 1
Value = Value * 10
i = i + 1
Loop
sTemp = NumberFormat2(Value,1,DecPlaces,DecPlaces, False)
If i < 10 Then
sTemp = sTemp & "E" & "-0" & i
Else
sTemp = sTemp & "E" & "-" & i
End If
Else 'Value = 1; format with as many zeros as specifid by DecPlaces variable
sTemp = NumberFormat2(Value,1,DecPlaces,DecPlaces,False) & "E+00"
End If

If bNeg Then
'append "-" to beginning of string representation
sTemp = "-" & sTemp
End If

Return sTemp
End Sub

Replies
0
Views
512
Android Question Musical notation
Replies
1
Views
327
Replies
3
Views
738
Replies
3
Views
2K
Replies
2
Views
1K