B4J Question BigDecimal as parameter using Inline Java

brianoh

Member
Licensed User
Longtime User
It's certainly great to have the BigDecimal functionality in B4J. I need to pass the BigDecimal value to an InLine Java function and I cannot determine how to do that. I also need to receive a BigDecimal result.

While I can and have converted the Java function to B4J code and it works fine, for the purpose of this exercise and for future usage I would like to use InLine Java code also.

Currently I am passing the BigDecimal as a String and receiving the result as a String. While this works OK, the ability to pass and receive a Java BigDecimal would be preferable.

Is there a way to do that? If so, an example would be good.
 

Daestrum

Expert
Licensed User
Longtime User
Here's how I use them in inline code (but I don't use the library)

B4X:
dim BigDecimal as JavaObject
...
 Log(BigDecimal)
 Log(inlineCode("bigDecimaltoString",BigDecimal))
End Sub
Sub inlineCode(name As String,arg As Object) As Object
 Return asJO(Me).RunMethod(name,Array(arg))
End Sub
Sub asJO(o As JavaObject) As JavaObject
  return o
End Sub
...
#if java
public static String bigDecimaltoString(java.math.BigDecimal ob){
 return ob.toString();
}
#end if
 
Upvote 0

brianoh

Member
Licensed User
Longtime User
Here's how I use them in inline code (but I don't use the library)

B4X:
dim BigDecimal as JavaObject
...
Log(BigDecimal)
Log(inlineCode("bigDecimaltoString",BigDecimal))
End Sub
Sub inlineCode(name As String,arg As Object) As Object
Return asJO(Me).RunMethod(name,Array(arg))
End Sub
Sub asJO(o As JavaObject) As JavaObject
  return o
End Sub
...
#if java
public static String bigDecimaltoString(java.math.BigDecimal ob){
return ob.toString();
}
#end if

Thanks for that info. I did not realize that I could use the JavaObject for BigDecimal.

I do prefer to use B4J resources where possible, but perhaps there is no way to extract the Java Bigdecimal from the B4J BigDecimal.

In this instance, because of the amount of code involved, I will continue using the B4J solution for BigDecimal, however I'll look at using your technique in the future.
 
Upvote 0
Top