This question already has answers here:
ultimate short custom number formatting - K, M, B, T, etc., Q, D, Googol
(3 answers)
Closed 6 months ago.
Hello How I can round that number without using custom formats like this "[>999999]0.0,,\M;[>999]0.0,\K;0"
Because if y use the custom format with this formula '="EXAMPLE "&E24' puts the value without that format.
try:
="example "&IF(A1<1000, A1,
IF(A1<1000000, TEXT(A1/1000, "#.0")&"K",
IF(A1<1000000000, TEXT(A1/1000000, "#.0")&"M",
IF(A1<1000000000000, TEXT(A1/1000000000, "#.0")&"B",
TEXT(A1/1000000000000, "#.0")&"T"))))
Related
This question already has answers here:
How to properly format currency on ios
(8 answers)
How to input currency format on a text field (from right to left) using Swift?
(9 answers)
Closed 4 years ago.
I have a values like that: 100, 1220, 10015 basically last 2 digits are cents and I need to convert to dollar (currency) format similar to:
1.00, 12.20, 100.15
Can somebody suggest a quick implementation?
var a = 1011
var b = Double(a) / 100
This question already has answers here:
A way to round Floats down
(11 answers)
Closed 6 years ago.
I have number num = 24.89808 and want to round it to 24.89
How can i do it?
i tried num.round(2) but it gives me 24.9 also number_to_currency=>24.90
If you are talking about rounding, 24.9 is by all means the correct result. Whether you are interested in ceiling it, here you go:
(24.89808 * 100).floor / 100.0
#⇒ "24.89"
First convert that into a decimal and then round it two two places,
Try this command,
num.to_d.round(2, :truncate).to_f
2.2.4 :040 > num = 24.89808
=> 24.89808
2.2.4 :041 > num.to_d.round(2,:truncate).to_f
=> 24.89
This question already has answers here:
Concatenation of tables in Lua
(13 answers)
Closed 7 years ago.
Is there an easy way to concatenate two tables which are sequences? For example
a = {1, 2, 3}
b = {5, 6, 7}
c = cat(a,b)
where c would be the table {1,2,3,5,6,7}?
function cat(t, ...)
local new = {unpack(t)}
for i,v in ipairs({...}) do
for ii,vv in ipairs(v) do
new[#new+1] = vv
end
end
return new
end
It uses iteration to add the elements of each array to a new one.
It's also worth noting that {unpack(t)} will only work if you have less than a specific number of elements, due to how tuples work in Lua. This varies across versions and depending on what you're doing, but if it's small you probably have nothing to worry about.
This question already has answers here:
Search for an item in a Lua list
(12 answers)
Lua find a key from a value
(3 answers)
Closed 9 years ago.
I have this table:
maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}
How can I make a script so if 1702169 (for example) is picked from the table, it prints ''That's the number''?
The easiest way to do what (i think) you want is with pairs() function. This is a stateless iterator which you can read more about here: http://www.lua.org/pil/7.3.html
If you simply want to scan through the entire table and see if it contains a value, then you can use this simple code:
local maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}
local picked = 1702169
for i, v in pairs(maps) do
if v == picked then
print("That's the number")
break
end
end
The above code will iterate through the whole table where i is the key and v is the value of the table[key]=value pairs.
I am slightly unclear about your end goal, but you could create this into a function and/or modify it to your actual needs. Feel free to update your original post with more information and I can provide you with a more specific answer.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to format a number with padding in Erlang
I developed this function :
check() ->
case get_val(Text, H) of
{ok, {Montant}} -> io:format("~s", [Montant]);
{error, pas_echeance} -> io:format("erreur")
end.
this function displayed Montant, this is an example of Montant :45
My goal is to convert this value "45" (which denotes Tunisian dinars) in the "45000" form (so I would have Tunisian millime -- each dinar consist of 1000 millimes).
Why dont you convert the value to integer (using list_to_integer("45") or list_to_integer(get_val(Text,H)) and multiply it by 1000.