简体   繁体   中英

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]) 在此处输入图片说明 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM