I'm trying to make a calculator app, and when the answer comes out to a decimal, the result has a lot of zeros on the end of it (i.e 0.500000). I'm trying to remove these zeros, and I have a "while" block testing if the last character is a zero, then using a segment block to extract the text without the last character. This isn't working, and I'm still getting the same results. I've posted my code here (I store the output of the calculation in a variable called "global output" and call the decimalTruncate procedure if global output has a "." in it).

Any suggestions?

Welcome Mary.

Perhaps

### round

Returns the given number rounded to the closest integer. If the fractional part is < .5 it will be rounded down. It it is > .5 it will be rounded up. If it is exactly equal to .5, numbers with an even whole part will be rounded down, and numbers with an odd whole part will be rounded up. (This method is called round to even.)

or

### format as decimal

Formats a number as a decimal with a given number of places after the decimal point. The number of places must be a non-negative integer. The result is produced by rounding the number (if there were too many places) or by adding zeros on the right (if there were too few).

as described in * Math blocks

Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles

How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Also look here http://kio4.com/appinventor/index.htm and here http://www.imagnity.com/tutorial-index/ for more tutorials.

Learn about components http://ai2.appinventor.mit.edu/reference/components/

and visit the Library http://appinventor.mit.edu/explore/library Help>Library on the MENU

Thanks! I'll try using the format as decimal function.

The built-in rounding functions work as a temporary solution, but I want a way to round only when there's unnecessary zeros at the end. (i.e show the full 1.45836583 but round 1.5000000 to 1.5)

I have also created a topic about this problem, you can look this-

You can try this also

First place these blocks-

Next place these blocks-

Last place these blocks-

You can run the code by calling this procedure-

This has to work. I have made an app with this procedure and its working properly

Thank you! It works perfectly!