Reputation: 15
I want to show fractions instead of decimal value in a textView(answerview)
For example - 1.0625 (This value is an answer from some calculation)
I want to show 1.0625 in fractions (Added a sample image [Required fraction image])
like 1(1/16) in textView.
This is not a constant value, the value keeps changing according to user calculations, so for every answer I want to convert into fractions and display
Sujay
Upvotes: 2
Views: 1996
Reputation: 1596
Use kexanie to do that
In your case you should set text in your MathView
[read kexanie README.md]
String text = "$$" + var1 + "\\frac{" + var2 + "}{" + var3 + "}$$";
Here var1 = 1
, var2 = 1
and var3 = 16
Add a MathView in your xml
<io.github.kexanie.library.MathView
android:id="@+id/formula"
android:layout_width="match_parent"
android:layout_height="wrap_content"
auto:engine="KaTeX"
>
</io.github.kexanie.library.MathView>
Then in onCreate() method
MathView mathv = (MathView) findViewById(R.id.formula);
and finally set your formula to mathv
mathv.setText(text);
Or you can use other libraries mentioned here
Upvotes: 4