sujay nambiar
sujay nambiar

Reputation: 15

How to display fraction instead of decimal (double) in android TextView (answerview)

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]) enter image description here 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

Answers (1)

Md. Nasir Uddin Bhuiyan
Md. Nasir Uddin Bhuiyan

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 + "}$$";

enter image description here

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

Related Questions