[Free] Number formatting 3.0 - My first Extension

My first extension - number formatting.


Hi this is my first extension! hope you enjoy it
Publish date: 2020-10-19T19:20:00Z
Current version: 3
Current version publish date: 2020-11-11T15:00:00Z

Write a short description


This is a simple extension that you can use to format numbers to default formats, or to a custom one

Add a picture of all the blocks



Format
Formats a number to a default format.
number ~ int ~ number to be formatted, in meters, bytes or grams
format format to:

  1. cm
  2. km
  3. GB
  4. MB
  5. kg

CustomFormat
customize the formatting of a number.
number ~ int ~ the number to be formatted
prefix and sufix ~ Strings ~ prefix or sufix your number with anything. leave an empty string if you don't want to prefix/sufix
multiplyFor ~ int ~ multiply your number for other. if you don't want to use this, put 1.
Separate
put a separator into your number.
number ~ the number you want to add separator
separator ~ the separator you want to use in your number
Indirect Methods
These are methods that will raise the indirect formatting event with the value instead of returning it. useful if you want to do something after formatting.
Error
error Message ~ int
an error occured
1 = you must choose a valid default format: Direct Method
2 = you must choose a valid default format: Indirect Method
IndirectFormatting
Event raised when you use indirect methods
value ~ the return value of the method.

Include a Download link here


If you want version 1, See here.

prior versions

Version 2
com.appybuilder.hguim150.Number_formatter.aix (7.8 KB)

Version 3 AIX:

com.appybuilder.hguim150.Number_formatter.aix (7.8 KB)

Hope you liked!!!

  • 1
  • 2
  • 3
  • 4
  • 5
0 voters
4 Likes

Great work :+1::+1:
P.S: seems that the download links aren't functionable , you need to re-upload them here, too.

1 Like

unfortunately, i don't have the link for the version 1 but i think no one will want version 1. i will update version 2.

1 Like

Looks like a handy extension GuiM_Haes, well done.

... Technically, your code is applying a unit to a value - does that mean a later version will provide conversions between units?

yes. I used units as the formats.

probably. but if you want to convert units on this version you can use CustomFormat or IndirectCustomFormat.

Could somebody provide an example of formatting? like take a 1000000 number and make it into $1,000,000?
Would it be something like: call Number_formatter1.CustomFormat
number = 1000000
prefix = $
sufix = ""
multiplyFor = 1000
?
Or Number_formatter1.Separate
number = 1000000
separator = "."

Sorry for my ignorance...

Why not try it out with the extension, looks like it is all there (custom format)

Thanks!, I know how to do it the long way. I was looking into an extension to simplify the code. But thanks for pointing this out to me.

I wrote a test code and the results don't make sense, I am obviously doing something stupid wrong, but don't know what.

The indirect methods seem to be doing nothing... I am missing something obvious.

Like this ?

image

1 Like

You should use custom format, with the value of separator. You should combine your methods.

err...

@Julio_Spinelli

It should be noted that, in App Inventor, as soon as you start "formatting" a number, it becomes a string. To use it as a number after "formatting" one has to convert it back to a number - remove all formatting.

Ok. It is returning strings so error.
Use join $ and separate with , the number you want.
P.S. if you want currencies you should specify wich dollar type you want (U.S., Canada, etc. Use $)


And with the result in the screen of the emulator (without the errro)

I need a dot as a separator, only USA uses ",", it works with a "," but not with "." :frowning:

Thanks for your reply and example!

That's strange.

you are wrong. I am not from U.S. and , is used.

1 Like

Show thousandizer procedure please.

Is it the same as in github?

I stand corrected! I should have said more than half the world uses "." for separation. For a detailed list see: https://en.wikipedia.org/wiki/Decimal_separatorList of Countries using "." and "," for thousands as a separator

Thanks for the correction!