<div dir="ltr">I'm doing something very similar, this is what I use:<div><div><span class="" style="white-space:pre"><br></span></div><div>local rate = string.format("%.4f", currency]["rate"])</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 23, 2015 at 8:45 AM, Ítalo Rossi <span dir="ltr"><<a href="mailto:italorossib@gmail.com" target="_blank">italorossib@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yep, it's available and defaults to 6 decimal places, but looks like it's not a Lua issue...</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Mar 23, 2015 at 9:05 AM, Bote Man <span dir="ltr"><<a href="mailto:bote_radio@botecomm.com" target="_blank">bote_radio@botecomm.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I’m not much of a programmer, but can’t you specify a format to %f to force it to return 4 decimal places?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Or is that not available in Lua?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Bote<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> John Carpenter<br><b>Sent:</b> Monday, 23 March, 2015 06:59<br><b>Subject:</b> Re: [Freeswitch-users] Problem with LUA dbh:query in Freeswitch<u></u><u></u></span></p></div></div><div><div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">Thats it, changed connection to a pgsql:// dsn and I get four decimal places, changed it back to ODBC and back to 3 decimal places. <u></u><u></u></p></div><p class="MsoNormal">Thanks very much, been driving me mad<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">On 23 March 2015 at 10:23, Steven Ayre <<a href="mailto:steveayre@gmail.com" target="_blank">steveayre@gmail.com</a>> wrote:<u></u><u></u></p><div><p class="MsoNormal">Have you tried a pgsql:// dsn? In case the ODBC driver is having some truncating effect.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p><div><div><div><p class="MsoNormal">On 22 March 2015 at 02:06, John Carpenter <<a href="mailto:carpenter.john@gmail.com" target="_blank">carpenter.john@gmail.com</a>> wrote:<u></u><u></u></p></div></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><div><div><div><div><p class="MsoNormal" style="margin-bottom:12.0pt">I am trying to use Lua to retrieve some currency conversion rates from a postgres database. It works but the numeric field value is only returning the first three decimal places although if I list the data in postgres it has four decimal places. I may be doing something daft as I am quite new to Lua, sample code is below. Any ideas appreciated<u></u><u></u></p></div><p class="MsoNormal">regards, John<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal"><b><span style="font-family:"Courier New";color:black;background:#f3f3f3">local</span></b><span style="font-family:"Courier New";color:black;background:#f3f3f3"> dbh = freeswitch.Dbh(<b>"odbc://fs_odbc:fs_user:password"</b>) <br><b>if</b> dbh:connected() == <b>false</b> <b>then</b> <br> freeswitch.consoleLog(<b>"notice"</b>, <b>"dp.lua cannot connect to database"</b> .. dsn .. <b>"\n"</b>) <br> <b>return</b> <br><b>end</b> <br><b>assert</b>(dbh:connected()) <br><br>e_rate = <b>1.123456789</b> <br><b>-- just a test</b> to see decimal places<br>freeswitch.consoleLog(<b>"info"</b>,<b>string.format</b>(<b>" e_rate = %f"</b>, e_rate)) <br><br><b>local</b> <b>function</b> eur2usd() <br> <b>local</b> sql = <b>"select eur2usd from currency order by id desc limit 1"</b> <br> dbh:query(sql, <b>function</b>(row) <br> e_rate = row.eur2usd <br> <b>end</b>) <br><b>end</b> <br><br><b>local</b> <b>function</b> eur2gbp() <br> <b>local</b> sql = <b>"select eur2gbp from currency order by id desc limit 1"</b> <br> dbh:query(sql, <b>function</b>(row) <br> e_rate = row.eur2gbp <br> <b>end</b>) <br><b>end</b> <br><br>eur2usd() <br>freeswitch.consoleLog(<b>"info"</b>,<b>string.format</b>(<b>" euro2usd = %f"</b>, e_rate)) <br>eur2gbp() <br>freeswitch.consoleLog(<b>"info"</b>,<b>string.format</b>(<b>" euro2gbp = %f"</b>, e_rate))</span><u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div><p class="MsoNormal"><u></u> <u></u></p></div></div></blockquote></div></div></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div></div><br></div></div><span class="">_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">Ítalo Rossi<br></div></div>
</font></span></div>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br></blockquote></div><br></div>