# Android QuestionSOLVED: 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

#### Erel

##### B4X founder
Staff member
Licensed User
Longtime User
Converting to string is not a good solution.

B4X:
``````Dim f As Float = 1.234
Dim i As Int = f
Dim ff As Float = f - i 'you might want to use Abs(f - i)``````

#### CosmicFlux

##### Member
Converting to string is not a good solution.

B4X:
``````Dim f As Float = 1.234
Dim i As Int = f
Dim ff As Float = f - i 'you might want to use Abs(f - i)``````

Thank you!

### Similar Threads

Replies
28
Views
10K
Android Question LSet equivalent
Replies
2
Views
589
Replies
10
Views
3K
Replies
45
Views
5K
Replies
9
Views
2K