<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title>www.ritlabs.com [Topic: Regex needed for decimal place]</title>
		<link>http://www.ritlabs.com</link>
		<description>New posts in Regex needed for decimal place of  forum at www.ritlabs.com [www.ritlabs.com]</description>
		<language>en</language>
		<docs>http://backend.userland.com/rss2</docs>
		<lastBuildDateTag>Sun, 13 Feb 2005 12:40:47 +0200</lastBuildDateTag>		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3995/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			You're the best Marck, thanks very much for your help.. &nbsp; <br />
			<i>13 February 2005 12:40:47, <a href="http://www.ritlabs.com/en/forums/">moz zer</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3995/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3995/</guid>
			<pubDate>Sun, 13 Feb 2005 12:40:47 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3992/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			Okay - only thing I'll say is change the .001 to .005 if you want the dec2 QT to round instead of truncate <img src="http://www.ritlabs.com/bitrix/images/main/smiles/5/icon_wink.gif" border="0" data-code=";-)" data-definition="SD" alt=";-)" style="width:16px;height:16px;" title="" class="bx-smile" /><br /><br />Enjoy!<br /><br /> <br />
			<i>13 February 2005 05:37:27, <a href="http://www.ritlabs.com/en/forums/">Marck Pearlstone</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3992/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3992/</guid>
			<pubDate>Sun, 13 Feb 2005 05:37:27 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3989/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			Yep, works great! &nbsp;Well, except for when I try the decimal justification method.. amounts under 100.00 get wiped out (nothing is displayed). &nbsp;Though, $ 100.00 justifies nicely with $1000.00.<br /> <br />
			<i>12 February 2005 17:16:24, <a href="http://www.ritlabs.com/en/forums/">moz zer</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3989/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3989/</guid>
			<pubDate>Sat, 12 Feb 2005 17:16:24 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3988/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			Ok, that didn't take long to understand! &nbsp;Only seemed complicated at first glance.. that's great that you can call other templates! &nbsp;That'll save a lot of wasted space when I end up having 6 or 7 templates for each country.. this way, I just call a QT like 'usa3' if I have 3 items to ship to the States.<br /> <br />
			<i>12 February 2005 15:38:02, <a href="http://www.ritlabs.com/en/forums/">moz zer</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3988/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3988/</guid>
			<pubDate>Sat, 12 Feb 2005 15:38:02 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3987/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			yikes.. getting complicated now. &nbsp;<img src="http://www.ritlabs.com/bitrix/images/main/smiles/5/icon_wink.gif" border="0" data-code=";)" data-definition="SD" alt=";)" style="width:16px;height:16px;" title="" class="bx-smile" /> &nbsp;I'll take a look at this and see what I can learn. &nbsp;Thanks very much for your help on this!<br /> <br />One other thing I meant to mention... when I show the calculated exchange rate for the item subtotal and then the shipping amount, it rounds the value down. &nbsp;So if it was actually $33.057 for example, it would display $33.05. &nbsp;But then when I total everything (with exchange rate), the value is correct.. although it appears to be 1 or 2 cents more than if you simply added the two calculated amounts. &nbsp;I'm betting I'll have some frugal customers catching this.. if fixing it is much more complicated, I'll just leave it as it is.<br /> <br />Thanks so much for all this..<br /> <br />
			<i>12 February 2005 15:29:19, <a href="http://www.ritlabs.com/en/forums/">moz zer</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3987/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3987/</guid>
			<pubDate>Sat, 12 Feb 2005 15:29:19 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3986/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			Okay. Here's where it gets interesting.<br /><br /><br />====quote====<br />moz zer wrote:<br />The only thing is, if I enter $10, it doesn't append the ".00" to the end of it. Is there an easy fix for that? <br />=============<br /><br />That's what "+ 0.001" is for. It adds decimal places. The regex then trims it to the first two.<br /><br />What we now should do is put the "2 decimals" logic into a callable QT - call it dec2 for example.<br /><span class="bx-font" style="font-family:Courier"><br />%SETPATTREGEXP="\d*\.\d\d"%-<br />%REGEXPMATCH='%Calc("%_1 + 0.001")'%-<br />%subpatt(1)%-<br /></span><br /><br />then you call the function like this:<br /><br /><span class="bx-font" style="font-family:Courier"><br />%qinclude(dec2,%_total)<br /></span><br /><br />because you'll need to perform the procedure on each of the totaled figures.<br /><br />Subpatt(1) selects and uses the 1st match result (in this case the only result).<br /><br />So, your code looks like this:<br /><span class="bx-font" style="font-family:Courier"><br />%VARitemA=%InputBox('Price of item #1 (C$):') %-<br />%VARitemB=%InputBox('Price of item #2 (C$):') %-<br />%VARitemC=%InputBox('Price of item #3 (C$):') %-<br />%VARshipping=%InputBox('SHIPPING cost (C$):') %-<br />%VARexchange=%InputBox('EXCHANGE rate (2 dec places): ') %-<br />%_subtotal1=%calc("%VARitemA + %VARitemB + %VARitemC")%-<br />%_subtotal2=%calc("%_subtotal1 + %VARshipping")%-<br />%_total=%calc("%_subtotal2 / %VARexchange")%-<br /><br />Item subtotal: $%qinclude(dec2,%_subtotal1)<br />Subtotal (with shipping): $%qinclude(dec2,%_subtotal2)<br />Grand total after exchange (%VARexchange%Chr(37)): $%qinclude(dec2,%_total)<br /></span><br /><br />If you wanted to justify the decimal place, you can modify dec2 to align the dots - here's an example for 4 digits ... amounts up to 9999<br /><br /><span class="bx-font" style="font-family:Courier"><br />%SETPATTREGEXP="[\s\d]{4}\.\d\d"%-<br />%REGEXPMATCH=' &nbsp; &nbsp;%Calc("%_1 + 0.001")'%-<br />%subpatt(1)%-<br /></span> <br />
			<i>12 February 2005 15:12:32, <a href="http://www.ritlabs.com/en/forums/">Marck Pearlstone</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3986/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3986/</guid>
			<pubDate>Sat, 12 Feb 2005 15:12:32 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3984/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			That's great, thank you so much Marck! &nbsp;Works like a charm!<br /> <br />What is %SUBPATT(1) supposed to do? &nbsp;It didn't make a difference if I left it out.<br /> <br />So here's my final code.. it *seems* to work ok, please let me know if you see any problems before I start using it with real customers!<br /><br />The only thing is, if I enter $10, it doesn't append the &quot;.00&quot; to the end of it. &nbsp;Is there an easy fix for that?<br /><br />the code:<br />
====code====
<pre>%VARitemA=%InputBox('Price of item #1 (C$):') %-
%VARitemB=%InputBox('Price of item #2 (C$):') %-
%VARitemC=%InputBox('Price of item #3 (C$):') %-
%VARshipping=%InputBox('SHIPPING cost (C$):') %-
%VARexchange=%InputBox('EXCHANGE rate (2 dec places): ') %-

%SETPATTREGEXP="(&#92;&#92;d*&#92;&#92;.&#92;&#92;d&#92;&#92;d)"%- 

%_subtotal1=%calc("%VARitemA + %VARitemB + %VARitemC + 0.001")%-
%_subtotal2=%calc("%_subtotal1 + %VARshipping")%-
%_total=%calc("%_subtotal2 / %VARexchange")%-

Item subtotal: $%REGEXPMATCH="%_subtotal1"
Subtotal (with shipping): $%REGEXPMATCH="%_subtotal2"
Grand total after exchange (%VARexchange%Chr(37)): $%REGEXPMATCH="%_total"</pre>
============= <br />
			<i>12 February 2005 11:24:48, <a href="http://www.ritlabs.com/en/forums/">moz zer</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3984/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3984/</guid>
			<pubDate>Sat, 12 Feb 2005 11:24:48 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3981/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			This may help:<br /><br />%_total=%calc("%VARitemA + %VARitemB + %VARitemC + %VARitemD + 0.001")%-<br />%SETPATTREGEXP="(\d*\.\d\d)"%-<br />%REGEXPMATCH="%_total"%-<br /><br />total: %SUBPATT(1)<br /> <br />
			<i>12 February 2005 09:32:28, <a href="http://www.ritlabs.com/en/forums/">Marck Pearlstone</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3981/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3981/</guid>
			<pubDate>Sat, 12 Feb 2005 09:32:28 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
		<item>
			<title>Regex needed for decimal place</title>
			<description><![CDATA[<b><a href="http://www.ritlabs.com/en/forums/forum6/topic921/message3980/">Regex needed for decimal place</a></b> <i>how to turn $39.5 into $39.50?</i> in forum <a href="http://www.ritlabs.com/en/forums/forum6/">The Bat! - Templates and Macros</a>. <br />
			I wondered if anyone might be so kind as to help me with a small template problem I once gave up on but am now giving another try..<br /> <br />I have MyMacros 1.11 and want to use %RegExp with %InputBox so that I can enter several dollar values into a series of %InputBox popups, store them in variables, total them up (I have this part working fine).. then make sure the total is rounded to 2 decimal places before displaying it in the message.<br /> <br />ie. if my total comes out to $39.5 or $295.5, I want it to change it to $39.50 or $295.50 respectively. &nbsp;But if it's $9.99 for example, I don't want it to do anything.<br /> <br />I'm pretty sure I have to use %RegExp to look for any \d (digit) after a '.' where the next character is null (or anything other than a digit), then append a &quot;0&quot; onto the end of it.. but I think maybe the syntax is confusing me! &nbsp;<img src="http://www.ritlabs.com/bitrix/images/main/smiles/5/icon_sad.gif" border="0" data-code=":(" data-definition="SD" alt=":(" style="width:16px;height:16px;" title="" class="bx-smile" /><br /> <br />Anyone be so kind as to help me out here?<br /> <br />This is all I have so far:<br /> <br />
====code====
<pre>%VARitemA=%InputBox('price of item one: $') %-
%VARitemB=%InputBox('price of item two: $') %-
%VARitemC=%InputBox('price of item three: $') %-
%VARitemD=%InputBox('price of item four: $') %-

total: %calc("%VARitemA + %VARitemB + %VARitemC + %VARitemD")</pre>
=============
<br /> <br />I guess I probably need to put the total into a variable as well to evaluate it??<br /> <br />
			<i>12 February 2005 03:33:59, <a href="http://www.ritlabs.com/en/forums/">moz zer</a>.</i>]]></description>
			<link>http://www.ritlabs.com/en/forums/forum6/topic921/message3980/</link>
			<guid>http://www.ritlabs.com/en/forums/forum6/topic921/message3980/</guid>
			<pubDate>Sat, 12 Feb 2005 03:33:59 +0200</pubDate>
			<category>The Bat! - Templates and Macros</category>
		</item>
	</channel>
</rss>
