<div dir="ltr"><div>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<br><br></div>regards, John<br><div><br>
<div>
<span style="font-family:monospace"><span style="font-weight:bold;color:rgb(255,255,84);background-color:rgb(255,255,255)"><br></span></span>
<div>
<span style="color:rgb(0,0,0)"><span style="background-color:rgb(243,243,243)"><span style="font-family:monospace,monospace"><span style="font-weight:bold">local</span> dbh = freeswitch.Dbh(<span style="font-weight:bold">"odbc://fs_odbc:fs_user:password"</span>)
<br><span style="font-weight:bold">if</span> dbh:connected() == <span style="font-weight:bold">false</span> <span style="font-weight:bold">then</span>
<br> freeswitch.consoleLog(<span style="font-weight:bold">"notice"</span>, <span style="font-weight:bold">"dp.lua cannot connect to database"</span> .. dsn .. <span style="font-weight:bold">"</span><span style="font-weight:bold">\n</span><span style="font-weight:bold">"</span>)
<br> <span style="font-weight:bold">return</span>
<br><span style="font-weight:bold">end</span>
<br><span style="font-weight:bold">assert</span>(dbh:connected())
<br>
<br>e_rate = <span style="font-weight:bold">1.123456789</span>
<br><span style="font-weight:bold">-- just a test</span>
to see decimal places<br>freeswitch.consoleLog(<span style="font-weight:bold">"info"</span>,<span style="font-weight:bold">string.format</span>(<span style="font-weight:bold">" e_rate = %f"</span>, e_rate))
<br>
<br><span style="font-weight:bold">local</span> <span style="font-weight:bold">function</span> eur2usd()
<br> <span style="font-weight:bold">local</span> sql = <span style="font-weight:bold">"select eur2usd from currency order by id desc limit 1"</span>
<br> dbh:query(sql, <span style="font-weight:bold">function</span>(row)
<br> e_rate = row.eur2usd
<br> <span style="font-weight:bold">end</span>)
<br><span style="font-weight:bold">end</span>
<span style></span><br>
<br><span style="font-weight:bold">local</span> <span style="font-weight:bold">function</span> eur2gbp()
<br> <span style="font-weight:bold">local</span> sql = <span style="font-weight:bold">"select eur2gbp from currency order by id desc limit 1"</span>
<br> dbh:query(sql, <span style="font-weight:bold">function</span>(row)
<br> e_rate = row.eur2gbp
<br> <span style="font-weight:bold">end</span>)
<br><span style="font-weight:bold">end</span>
<br>
<br>eur2usd()
<br>freeswitch.consoleLog(<span style="font-weight:bold">"info"</span>,<span style="font-weight:bold">string.format</span>(<span style="font-weight:bold">" euro2usd = %f"</span>, e_rate))
<br>eur2gbp()
<br>freeswitch.consoleLog(<span style="font-weight:bold">"info"</span>,<span style="font-weight:bold">string.format</span>(<span style="font-weight:bold">" euro2gbp = %f"</span>, e_rate))<br></span></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(243,243,243)"><span style="font-family:monospace,monospace">
</span></span></span><br></div>
</div></div>