This question already has answers here:
ultimate short custom number formatting - K, M, B, T, etc., Q, D, Googol
(3 answers)
Closed 1 year ago.
I've looked everywhere and haven't found any solutions to getting numbers in the "Trillions" to format with a trailing "T".
Here is the custom number format I'm currently using: [<999950]$0.00,"K";[<999950000]$0.00,,"M";$0.00,,,"B"
Which displays these numbers as so:
Is Google Sheets also able to make numbers in the Trillions format as $1.00T?
Thanks!
not possible. this "internal" formatting is by default able to work with only 3 types of numbers:
positive (1, 2, 5, 10, ...)
zero (0)
negative (-3, -9, -7, ...)
this can be somehow tweaked to show custom formatting like K, B, M but you always got only 3 slots you can use, meaning that you can't have trillions as the 4th type/slot
however, this would cover your needs:
=ARRAYFORMULA(IF(ABS(A:A)<10^3, A:A&"",
IF(1*ABS(A:A)<10^6, TEXT(A:A/10^3, "#.0\k"),
IF(1*ABS(A:A)<10^9, TEXT(A:A/10^6, "#.0\M"),
IF(1*ABS(A:A)<10^12, TEXT(A:A/10^9, "#.0\B"),
IF(1*ABS(A:A)<10^15, TEXT(A:A/10^12, "#.0\T"),
IF(1*ABS(A:A)<10^18, TEXT(A:A/10^15, "#.0\Q\a"),
IF(1*ABS(A:A)<10^21, TEXT(A:A/10^18, "#.0\Q\i"),
IF(1*ABS(A:A)<10^24, TEXT(A:A/10^21, "#.0\S\x"),
IF(1*ABS(A:A)<10^27, TEXT(A:A/10^24, "#.0\S\p"),
IF(1*ABS(A:A)<10^30, TEXT(A:A/10^27, "#.0\O"),
IF(1*ABS(A:A)<10^33, TEXT(A:A/10^30, "#.0\N"),
IF(1*ABS(A:A)<10^36, TEXT(A:A/10^33, "#.0\D"),
IF(1*ABS(A:A)<10^39, TEXT(A:A/10^36, "#.0\U"),
IF(1*ABS(A:A)<10^42, TEXT(A:A/10^39, "#.0\D\d"),
IF(1*ABS(A:A)<10^45, TEXT(A:A/10^42, "#.0\T\d"),
IF(1*ABS(A:A)<10^48, TEXT(A:A/10^45, "#.0\Q\a\d"),
IF(1*ABS(A:A)<10^51, TEXT(A:A/10^48, "#.0\Q\u\d"),
IF(1*ABS(A:A)<10^54, TEXT(A:A/10^51, "#.0\S\x\d"),
IF(1*ABS(A:A)<10^57, TEXT(A:A/10^54, "#.0\S\p\d"),
IF(1*ABS(A:A)<10^60, TEXT(A:A/10^57, "#.0\O\d"),
IF(1*ABS(A:A)<10^63, TEXT(A:A/10^60, "#.0\N\d"),
IF(1*ABS(A:A)<10^66, TEXT(A:A/10^63, "#.0\V"),
IF(1*ABS(A:A)<10^69, TEXT(A:A/10^66, "#.0\C"), ))))))))))))))))))))))))
Related
We have job numbers most with a leading 1, with 7 digits to follow. There is one set, that leads with a 6, and is 6 digits. I need a leading '0' on both
The below formula captures the '0', for job numbers leading with a 1, with 7 digits, but not the items leading with a 6, with 6 digits:
Z Sage ID = IF(LEFT('Sales
Force_Contract'[Account_Number__c],1)="1",CONCATENATE("0",'Sales
Force_Contract'[Account_Number__c]),'Sales Force_Contract'[Account_Number__c])
Here's what I tried, and received this error:
Z Sage ID = IF(LEFT('Sales
Force_Contract'[Account_Number__c],1)="1",IF(and('Sales
Force_Contract'[Account_Number__c]="6",CONCATENATE("0",'Sales
Force_Contract'[Account_Number__c]),'Sales Force_Contract'[Account_Number__c])))
'Too many arguments were passed to the AND function. The maximum
argument count for the function is 2.'
Can you help get on the right track?
The easiest way is to use operators that don't require you to add words like AND()
Read more about it here.
The following code should work:
Z Sage ID =
IF (
LEFT('Sales Force_Contract'[Account_Number__c],1) = "1" ||
LEFT('Sales Force_Contract'[Account_Number__c],1) = "6",
"0" & 'Sales Force_Contract'[Account_Number__c],
'Sales Force_Contract'[Account_Number__c]
)
How it works:
It checks if the left number is either a 1 or (Or = ||) a 6.
If yes, it adds a leading 0 (One & (&) to concatenate, two & (&&) to get the AND() function)
If no, it takes the original account number.
I'm trying to do the following in Google Sheets:
If the number in cell A1 has 4 decimals (for example "1.0001"), and if cell A1>B1 (for example A1=1.0001 and B1=0.0001), and if the string in cell C1 = "Good", then return (A1-B1)*10000.
Additionally:
If the number in cell A2 has 2 decimals (for example "1.01"), and if cell A2>B2 (for example A2=1.01 and B2=0.01), and if the string in cell C2 = "Great", then return (A2-B2)*100.
So far, I've come up with this IFS function:
=IFS((AND(A1>B1, C1="Good")), (A1-B1)*10000,(AND(A2>B2, C2="Great")),(A2-B2)*100,TRUE,"ERROR")
Which treats the two arguments A1>B1, C1="Good" / A2>B2, C2="Great", within the AND formula.
How can I add the decimal argument to the AND statement?
I thought of setting for something like :
=IFS((AND(A1>B1, C1="Good", **A1=(a number with 4 decimals)))**, (A1-B1)*10000,(AND(A2>B2, C2="Great", **A2=(a number with 2 decimals)))**,(A2-B2)*100,TRUE,"ERROR")
Where the statements:
A1=(a number with 4 decimals)
and
A1=(a number with 2 decimals)
would do the trick.
How do you formulate those missing "decimal statements"?
It depends if you mean exactly 4 decimal places, like 1.0001, or at least 4 decimals, which would include 1.000123.
You can test for decimals by using round (or roundup or rounddown) so in the first case:
=ifs(and(round(A1,3)<>A1,A1>B1,C1="Good"),(A1-B1)*10000,and(round(A2,1)<>A2,A2>B2,C2="Great"),(A2-B2)*100)
But if you wanted it to be exactly 4 decimals:
=ifs(and(round(A1,3)<>A1,round(A1,4)=A1,A1>B1,C1="Good"),(A1-B1)*10000,and(round(A2,1)<>A2,round(A2,2)=A2,A2>B2,C2="Great"),(A2-B2)*100)
you can solve this with one blow:
=ARRAYFORMULA(
IF((LEN(IFERROR(REGEXEXTRACT(TO_TEXT(A1:A), "\.(.*)")))=4) *
(A1:A>B1:B) * (C1:C="Good"), (A1:A-B1:B)*10000,
IF((LEN(IFERROR(REGEXEXTRACT(TO_TEXT(A1:A), "\.(.*)")))=2) *
(A1:A>B1:B) * (C1:C="Great"), (A1:A-B1:B)*100, )))
This question already has answers here:
Algorithm to list unique permutations of string with duplicate letters
(3 answers)
Closed 6 years ago.
char ary[10] = "AAABB";
There are 6!/(3!*2!) possible ways to arrange them. How do I find them all?
First, there are 5! / (3! * 2!) = 10 possible ways, not 6! / (3! * 2!). But I think this is your typo.
For this specific string "AAABB", you can do something like this:
Take away "BB", and treat "A"s as separators of "B" slots. Let _ (underscore) be the slot we can insert "B" in.
_A_A_A_
First, treat "BB" as two separated char, and insert them in. We can insert them in slot 1 & 2 ("BABAA"), 1 & 3 ("BAABA"), 1 & 4, 2 & 3, 2 & 4, 3 & 4. (6 in total)
Then, treat "BB" as one, and insert it in. We can insert it in slot 1 ("BBAAA"), 2 ("ABBAA"), 3, 4. (4 in total)
All 10 possible ways iterated.
I am new with Mathematica and I have one more task to figure out, but I can't find the answer. I have two lists of numbers ("b","u"):
b = {8.734059001373602`, 8.330508824111284`, 5.620669156438947`,
1.4722145583571766`, 1.797504620275392`, 7.045821078656974`,
2.1437334927375247`, 2.295629405840401`, 9.749038328921163`,
5.9928406294151095`, 5.710839663259195`, 7.6983109942364365`,
1.02781847368645`, 4.909108426318685`, 2.5860897177525572`,
9.56334726886076`, 5.661774934433563`, 3.4927397824800384`,
0.4570000499566351`, 6.240122061193738`, 8.371962670138991`,
4.593105388706549`, 7.653068139076581`, 2.2715973346475877`,
7.6234743784167875`, 0.9177107503732636`, 3.182296027902268`,
6.196168580445633`, 0.1486794884986935`, 1.2920960388213274`,
7.478757220079665`, 9.610332785387424`, 0.05088141346751485`,
3.940557901075696`, 5.21881311050797`, 7.489624788199514`,
8.773397599406234`, 3.397275198258715`, 1.4847171141876618`,
0.06574278834161795`, 0.620801320529969`, 2.075457888143216`,
5.244608900551409`, 4.54384757203616`, 7.114276285060143`,
2.8878711430358344`, 5.70657733453041`, 8.759173986432632`,
1.9392596667256967`, 7.419234634325729`, 8.258205508179927`,
1.185315253730261`, 3.907753644335596`, 7.168561412289151`,
9.919881985898002`, 3.169835543867407`, 8.352858871046699`,
7.959492335118693`, 7.772764587074317`, 7.091413185764939`,
1.433673058797801`};
and
u={5.1929, 3.95756, 5.55276, 3.97068, 5.67986, 4.57951, 4.12308,
2.52284, 6.58678, 4.32735, 7.08465, 4.65308, 3.82025, 5.01325,
1.17007, 6.43412, 4.67273, 3.7701, 4.10398, 2.90585, 3.75596,
5.12365, 4.78612, 7.20375, 3.19926, 8.10662};
This is the LinePlot of "b" and "u";
I need to compare first 5 numbers from "b" to 1st number in "u" and always leave the maximum (replace "b"<"u" with "u"). Then I need to shift by 2 numbers and compare 3rd, 4th, 5th, 6th and 7th "b" with 2nd "u" and so on (shift always => 2 steps). But the overlapping numbers need to be "remembered" and compared in the next step, so that always the maximum is picked (e.g. 3rd, 4th and 5th "b" has to be > than 1st and 2nd "u").
Possibly the easiest way would be to cover the maximums showed in the image throughout the whole function, but I am new to this software and I don't have the experience to do that. Still It would be awesome if someone would figure out how to do this with a function that would do what I have described above.
I believe this does what you want:
With[{n = Length # u},
Array[b[[#]] ~Max~ Take[u, ⌊{#-2, #+1}/2⌋ ~Clip~ {1, n}] &, 2 n + 3]
]
{8.73406, 8.33051, 5.62067, 5.1929, 5.55276, 7.04582, 5.55276, 5.55276, 9.74904,--
Or if the length of u and v are appropriately matched:
With[{n = Length # u},
MapIndexed[# ~Max~ Take[u, ⌊(#2[[1]] + {-2, 1})/2⌋ ~Clip~ {1, n}] &, b]
]
These are quite a lot faster than Mark's solution. With the following data:
u = RandomReal[{1, 1000}, 1500];
b = RandomReal[{1, 1000}, 3004];
Mark's code takes 2.8 seconds, while mine take 0.014 and 0.015 seconds.
Please ask your future questions on the dedicated Mathematica StackExchange site:
I think that there's a small problem with your data, u doesn't have as many elements as Partition[b,5,2]. Leaving that to one side, the best I could do was:
Max /# Transpose[
Table[Map[If[# > 0, Max[#, u[[i]]], 0] &,
RotateRight[PadRight[Partition[b, 5, 2][[i]], Length[b]],
2 (i - 1)]], {i, 1, Length[u]}]]
which starts producing the same numbers as in your comment.
As ever, pick this apart from the innermost expression and work outwards.
The output from Mathematica with the following operation FactorInteger[28851680048402838857] is as follows:
{{3897424303, 1}, {7402755719, 1}}
My question is: how could I go about extracting the two prime numbers (without the exponents) and assign them to an arbitrary variable?
I basically want to retrieve two primes, whatever they may be, and assign them some variables.
Ex: x0 = 3897424303 and x1 = 7402755719
Thanks!
The output is a list and you can use list manipulating functions like Part ([[ ]]) to pick the pieces you want, e.g.,
{x0, x1} = FactorInteger[28851680048402838857][[All, 1]]
or, without Part:
{{x0,dummy}, {x1,dummy}} = FactorInteger[28851680048402838857];
Implicit in your question is the issue of handing parts of the expression that is returned as output from functions such as FactorInteger. Allow me to suggest alternatives.
1. Keep all of the values in a {list} and access each element with Part:
x = First /# FactorInteger[7813426]
{2, 31, 126023}
x[[1]]
x[[3]]
2
126023
2. Store factors as values of the function x, mimicking indexation of an array:
(This code uses MapIndexed, Function.)
Clear[x]
MapIndexed[
(x[First##2] = First##1) &,
FactorInteger[7813426]
];
x[1]
x[3]
2
126023
You can see all the values using ? or ?? (see Information):
?x
Global`x
x[1]=2
x[2]=31
x[3]=126023