This may be a easy question to answer but I am a bit stumped and I have not studied Smarty long enough to figure it out.
I need to display numbers in a 3 digit format, ie:
8 = 008
18 = 018
118 = 118
To add some context, basically I am trying to edit a Prestashop template (never touched smarty before this). Currently the price is displayed as 1.223.014 and I would like to separate the last three digits so that I can format it differently from the first part of the price. Thus I would be able to do something like
<span class="abc">1.223</span>.<span class="xyz">014</span>
Not sure if there is a easier way to do this but basically I am currently dividing the current price by 1000 (to eliminate the last 3 digits) and now I am stumped on how to get the last 3 digits (works fine if the last three digits are above 99)
Your help is appreciated.
Thanks
Solution for your example
{"%03d"|sprintf:8}
Possible solution if you want the last 3 digits in any case
{'1.223.014'|substr:-3}
html:
<span class="abc">{'1.223.014'|substr:0:-4}</span>.<span class="xyz">{'1.223.014'|substr:-3}</span>
Note: This will not work if the number length is lower than 4
If you wanna check if there are dots inside the number, you can do this
{if '1.223.014'|substr_count:'.' > 0}
..dots inside..
{else}
..no dots inside..
{/if}
Tested with smarty 3.
Related
I will input numbers serially but not in consecutive cells, it would be random like this:
I want to highlight numbers from where the serial number is broken as shown (Since number 17 is missing so number 18 onwards all number are highlighted)
Please help me with a custom formula for the conditional formatting of this.
try this new approach:
=REGEXMATCH(A2&"", INDEX(TEXTJOIN("|", 1, "×",
SORT(IFERROR(1/(1/((IFERROR(SORT(UNIQUE(FLATTEN(IFERROR(SPLIT(A$2:A, ",")))))<>
SEQUENCE(MAX(FLATTEN(IFERROR(SPLIT(A$2:A, ","))))), TRUE))*
SEQUENCE(MAX(FLATTEN(IFERROR(SPLIT(A$2:A, ",")))))))), 1, 0))))
try:
=A2>INDEX(MAX(IFERROR((SEQUENCE(MAX(A$2:A))=SORT(A$2:A))*SEQUENCE(MAX(A$2:A)))))
update:
=REGEXEXTRACT(A2&"", "\d+,?")*1>INDEX(MAX(IFERROR((SEQUENCE(MAX(A$2:A))=
SORT(UNIQUE(FLATTEN(SPLIT(A$2:A, ",")))))*SEQUENCE(MAX(A$2:A)))))
Been looking all over and nothing comes up as far as a Google Sheets formula.
Let's say we have a value of 3.6875 feet. We can use the number format # ??/??, but it will give us a fractional value in feet (in this case, 3 11/16 feet).
How do we "grab" the 11/16 and multiply it by 12 to get the inches value (8.25), and then the really tricky part, how do we display the whole enchilada as 3'8¹/⁴" (yes, including the superscript)?
A1= 3.6875
B1=INT(A1)&"'-"&TRIM(TEXT(ROUND(MOD(A1,1)*12*16,0)/16,"# ??/??")&"""")
Output: 3'-8 1/4 "
UPDATED:
You can have a table to search the superscript
The idea to get the superscript: with above output (3'-8 1/4"): is to extract the fraction (1/4), search for the equivalent superscript in the table (¹/⁴), then replace it (3'-8 ¹/⁴"):
So basically we will need:
REGEXEXTRACT
VLOOKUP
REGEXREPLACE
SPREADSHEET DEMO: HERE
=arrayformula(
if(len(A2:A),INT(A2:A)&"'-
"®EXREPLACE(TRIM(TEXT(ROUND(MOD(A2:A,1)*12*16,0)/16,"#??/??")&""""),
"\d{1}\/\d+",
VLOOKUP(IFNA(
REGEXEXTRACT(TRIM(TEXT(ROUND(MOD(A2:A,1)*12*16,0)/16,"# ??/??")&""""),
"\d{1}\/\d+"),
"0/0"),
TABLE!A:B,2,0)),""))
Basically, what I want to do is look at the range information of a unified diff and know exactly which lines of code I should pay attention to.
For instance, this:
## -1827,7 +1827,7 ##
This tells me that in total only 1 line has changed, because the diff shows 3 lines above and below the change (so 7 - 6 = 1), and it also points me to the line 1830 (i.e. 1827 + 3).
To be more pedantic, this particular range information actually tells me that at line 1830, a line was removed (-), and at line 1830 a line was added (+).
Or to make that more obvious consider this range information for another diff:
## -878,15 +878,13 ##
What this is telling me is that at line 881 (878 + 3) 9 lines were deleted (15 - 6), but at line 881 only 7 lines were added (13 - 6).
So the question is, using a regex or some other Ruby string method, how do I pull out the above information easily?
i.e. how do I easily pull out this info:
Both The line numbers (i.e. just the 1827 or 878), which I can then add + 3 to determine the actual inline number I care about. It has to be both because both lines may not always be identical.
The number of lines affected (aka the 7, 15 or 13 right after the , in the above examples)
While I do that, how do I make sure to track the operation (addition or deletion) for each of the operations.
I tried slicing the string and going directly for a character -- e.g. myString[3] which gives me -, but that's the only character it reliably works for because the line numbers can be 1, 10, 100, 1000, 10000, etc. So the only way is to just scan the string and then parse it.
Edit 1
To add some code to show what I have tried.
Assume I have the contents of a diff in a variable called #diff_lines:
#diff_lines.each do |diff_line|
if diff_line.start_with?("##")
del_line_num_start = diff_line.split(/## /).second.split.first.split(/-/).second.split(/,/).first.to_i + 3
num_deleted_lines = diff_line.split(/## /).second.split.first.split(/-/).second.split(/,/).second.to_i - 6
add_line_num_start = diff_line.split(/## /).second.split.second.split(/\+/).second.split(/,/).first.to_i + 3
num_added_lines = diff_line.split(/## /).second.split.second.split(/\+/).second.split(/,/).second.to_i - 6
As you can see, the above works....but it is quite horrendous to look at and is OBVIOUSLY not very DRY.
Ideally I would like to be able to achieve the same thing, but just cleaner.
The general idea is to write a regular expression that has capture groups in it ((...)) to pick apart that string into something useful. For example:
diff_line.match(/\A##\s+\-(\d+),(\d+)\s+\+(\d+),(\d+)\s+##/)
This yields a MatchData object on a successful match. You can then apply this to some variables like:
if (m = diff_line.match(...))
a_start, a_len, b_start, b_len = m[1..4].map(&:to_i)
end
Then you can do whatever computations you need to do with these numbers.
If you're ever having trouble visualizing what a regular expression does, try a tool like Rubular to better illustrate the internals.
First of all I would like to apologize if this has been asked before, I just couldn't find the answer.
To the point:
My problem is as follows: I am using Crystal Reports for VS2010 and I have a field that should dispaly 1 or -1 based on an If check
If IsNull ({Orders.OrderReplacedBy})
Then 1
Else -1
It should display in my report 1 for null values of the field and -1 otherwise. Problem is that in my report I get only .00 no matter the value of the if test.
Furthermore I have another formula field that does of a sum of all the 1s and -1s showed on the report, and it seems to be working a little weird. In my database I have 772 total rows, of which 39 are NULL (so there should be 733 1s and 39 -1s with a sum of 694) and the displayed sum is 488. The code for the sum is as follows:
Sum({#N})
where N is the field where I calculate the 1s and -1s.
What I've tried so far:
changed the If test from IsNull to ToText({Orders.OrderReplacedBy})=""
changed the If test to {Orders.OrderReplacedBy}>0 as the OrderReplacedBy field in the database is numeric and there cannot be values less than zero, so the NULLs should just trigger the Else.
trid to change the display of the formula to "1" and ToNumber("1") nothing seems to work
I honestly have no more ideas of what else to try and I also have no knowledge of Crystal Reports (I am only working with it for 2 days and just need to modify a report on an existing app).
Any help would be appreciated,
Thanks :)
P.S.: I am working with Silverlight 4
Since no one answered I presume that this hasn't happened to anyone or isn't of much interest. But after doing some more research and trying out other stuff I've found a workaroud that I'll post (maybe someone else bumps to this, who knows?):
In the N formula (I don't know why it didn't work the last time I tried) I changed things like this:
If IsNull({Orders.OrderReplacedBy})
Then "1"
Else "-1"
Added a new formula that isn't used on the report called Numbers
If {#N}="1"
Then 1
Else -1
And then I changed the sum formula to match the intermediate field
Sum({#Numbers})
I still don't know the reason why the report didn't want to show me the numbers in the N formula, nor why the sum formula didn't calculate the correct sum.
I hope this is at least going to be useful to someone else,
Cheers!
In MediaWiki (wikipedia's) wiki syntax, is there a way to have a numbered list with a code block in the middle?
For example:
# Number 1
# Number 2
Indented section that will become a code block
# Number 3
# Number 4
What happens in MediaWiki is you end up with something like this:
1. Number 1
2. Number 2
Indented section that will become a code block
1. Number 3
2. Number 4
(Note how "Number 3" and "Number 4" are reset as 1 and 2... It looks like StackOverflow is much smarter than MediaWiki, i had to put my example in PRE tags to make it screw up!)
I know you can indent text using "#:" syntax...
# Number 1
# Number 2
#: Indented section that will merely be indented
# Number 3
# Number 4
...but I really would like to get the same visual CSS class for my code even if it's in a numbered list.
It gets even more entertaining with nested lists. This syntax...
# MainEntry 1
## Number 1
## Number 2
# MainEntry 2
## Number 1
## Number 2
Indented section that will become a code block
## Number 3
## Number 4
...becomes...
1. MainEntry 1
1. Number 1
2. Number 2
2. MainEntry 2
1. Number 1
2. Number 2
Indented section that will become a code block
1. 1. Number 3
2. Number 4
(Note how "Number 3" is now "1. 1.")
You could try the following wiki syntax, it works for me on 1.17
# one
#:<pre>
#::some stuff
#::some more stuff</pre>
# two
It is not perfect, because you end up with a more indent but it does allow one to use the wiki syntax for correctly formatted pre blocks over multiple lines.
As previously mentioned, the other proper way would be to use HTML mark up.
<ol>
<li>one</li>
<li>two</li>
<pre>some stuff
some more stuff</pre>
<li>three</li>
</ol>
Use html:
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
it will work in mediawiki.
Note from the example that I posted below, it is the </li> that makes it work properly.
This works fine in MediaWiki 1.17.0:
===Alternative way of using pre in numbered lists.===
# Numbered line 1.
# Numbered line 2.<pre>code line 1
code line 2</pre>
# Numbered line 3.
The secret is to replace the newlines with the
entity and write everything in one line.
Your issue is the subject of two bugs filled in the MediaWiki bug tracker in late 2004 and 2005 :
Bug 1115 - Newline as list item terminator is troublesome
Bug 1584 - Need method for multiparagraph list items, continuing numbered lists, and assigning specific numbers to list items
By reading them, you will find the solution is to not use the MediaWiki syntax but to rely on "pure" HTML.
I'm suggesting a different answer: don't do it.
I've attempted to use all the workarounds for this basic Mediawiki issue and found that they are all very imperfect. I've learned to live without numbers, and instead:
Use the splat (*) instead of (#) for all my lists
Continue to use the leading space for all my code blocks
This is far far simpler and maintainable than any workaround. Besides, use of any reference to a number is subject to change as the steps are edited - and this then becomes another maintenance issue.
In the above example the second indentation (::) is not necessary.
Just one indentation works fine (:) as follows:
# one
#:<pre>
#:some stuff
#:some more stuff</pre>
# two
Produces:
1. one
some stuff (just one indent level, not two)
some more stuff
2. two
You can also try adding a "blockquote" tag surrounding the "pre" tag, makes it look a little more polished.
== HAProxy Configuration ==
#'''File:''' /etc/haproxy/haproxy.cfg
<blockquote>
<pre>
global
log 127.0.0.1 local1 notice
maxconn 4096
#daemon
debug
crt-base /usr/local/haproxy/ssl
</pre>
</blockquote>
Which will indent the gray box in line with your bullets/numbers without using colons.