Android Question SOLVED: C modf Equivalent in B4A?

CosmicFlux

Member
Hi,

Is there a function that splits a Float into its integral and fractional parts? I've looked around, and the solutions I've come across seem to involve converting to strings, then pulling out the fractional as an index? Seems a bit clunky. Is there a better way?

For context, I have a C++ program that uses the modf function from cmath to achieve this. Is there an equivalent?

Thanks
 

CosmicFlux

Member
Hi Community,

After hacking away for a bit I managed to get what I'm after, using the code below:

Calculate SubProcedure:
Dim pointsValue = (kills / survivors) + (damageGiven / damageReceived)
Dim fractionalTest As String = pointsValue.SubString2(2,4)

Log("Raw Calculated Points : " & pointsValue)
Log("Fractional Stripped : " & fractionalTest)

If fractionalTest >= 75 Then
    pointsValue = Ceil(pointsValue)
Else If fractionalTest < 75 And fractionalTest >= 50 Then
    pointsValue = Floor(pointsValue) + 0.5
Else If fractionalTest < 50 Then
    pointsValue = Floor(pointsValue)
End If   

Log("Final Points Calculation : " & pointsValue)

I'd still be interested to know if anyone has had a use case for this, and what their solution was.

Happy coding!

Flux
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…