What can be the error in this float calculation? - variables

I always have a lot of troubles with variables: float, string and numbers.
Can anyone tell me why this doesn't work?
What did I wrong?
let beforeE = '2.18'
let nrzeros = '000'
let newnr = beforeE * 1.nrzeros
echo newnr
This gives as output 2000 and not 2180.
Why?
I tried to change variables with str2float and tried a few other things
but I receive only errors:
Using float as a string or Variable type mismatch
Tnx in advance.

let beforeE = 2.18 " or str2float('2.18')
let nrzeros = '000'
let newnr = beforeE * str2float(1.nrzeros)
echo newnr

Related

(SQR 4008) Unknown function or variable in expression

I have an SQR code like this:
begin-procedure SPL-REMOVE($Vndr_Name_Shrt_Usr, :$outputshrt)
Let $valid_chars_shrt = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -.:/'#0123456789#()=+%*"£$'
Let $invalid_chars_shrt = translate($Vndr_Name_Shrt_Usr, $valid_chars_shrt, '')
Let #invalid_shrt = length($invalid_chars_shrt)
If #invalid_shrt
Let $outputshrt = translate($Vndr_Name_Shrt_Usr, $invalid_chars_shrt, '')
Else
Let $outputshrt = $Vndr_Name_Shrt_Usr
End-if
end-procedure
And upon running the SQR, I am getting this error:
(SQR 4008) Unknown function or variable in expression: #0123456789#
Let $valid_chars_shrt = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -.:/'#0123456789#()=+%*"£$'
May I know why is that so? How can I avoid such error from coming up?
If this is truly the code:
Let $valid_chars_shrt = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -.:/'#0123456789#()=+%*"£$'
The problem lies with the single quote before the #012345678. It unbalances the quoted string. Change it to TWO single quotes '' (not a double-quote). That should work but unless I test it, no guarantees.

Interpolated strings in F#

I am trying to use the Entity Framework Core interpolated SQL query function in F# which requires a FormattableString. However to my surprise it doesn't function as I cannot find a way to convert a regular F# string to that type. I figured just doing what you do in C# would work but it doesn't. Here is the code I currently have:
let fromDbUser (u : Entity.User) =
{
name = u.Name
age = u.Age
phone = u.Phone
}
let mname = "Foo"
let ctx = new Entity.DatabaseContext()
ctx.User.FromSqlInterpolated($"Select * FROM User Where name = {mname};")
|> Seq.map(fromDbUser)
|> printfn "%A"
Running that block of code yields a compile error:
This token is reserved for future use
I have been trying to google around but I was unable to find any way to get this to work, any help would be most appreciated!
When this was asked, F# didn't have string interpolation.
Today though, there is an RFC for it that is merged in in F# 5.0 allowing string interpolation in F#.
The error was because the $ symbol is reserved (for 6 years+ as of writing), and will probably be used for string interpolation when it is added.
As Dave pointed out, interpolation isn't implemented yet.
But for methods that absolutely require an FormattableString or an IFormattable, you can use FormattableStringFactory.Create
let query (sql: FormattableString) =
printfn "%s" (sql.ToString(null, null))
let mname = "Foo"
let fstr = FormattableStringFactory.Create("Select * FROM User Where name = {0};", mname)
query fstr
It's available from F# 5.0.
> let mname = "Foo" ;;
val mname : string = "Foo"
> let str = $"Select * FROM User Where name = {mname};" ;;
val str : string = "Select * FROM User Where name = Foo;"
Check this out. https://learn.microsoft.com/en-us/dotnet/fsharp/whats-new/fsharp-50#string-interpolation

Adding two variables containing integer values

I have fetched integer data in two variables from different tables. I need to apply the add operation so that I can get the sum of the values in those variables. I am a beginner though so please try to help me out here. I tried the code in Model and the result I am getting is : Object of class CI_DB_mysqli_result could not be converted to int
$fromrequest = $this->db->query("SELECT Requests.sunit FROM Requests WHERE Requests.sid = 2");
$fromstock = $this->db->query("SELECT Stock.sunit FROM
Stock WHERE Stock.ssid = 5");
$sum = $fromrequest + $fromstock
first your queries are not definite. Look at "SELECT Requests.sunit FROM Requests", the query is going to list all Sunits in the table Requests. But you want to count or sum the sunit and assign them to the valuable $fromrequest the query like
$fromrequest = $this->db->query("SELECT count(Requests.sunit) as Units FROM Requests");
or
$fromrequest = $this->db->query("SELECT sum(Requests.sunit) as Units FROM Requests");
would results into an integer which would make your life easy. Try it and we see what we get. Good luck
check the values and better use active record..
$get_fromrequest = $this->db->select('sunit')->where('sid',2)->get("Requests");
$fromrequest = $get_fromrequest->row();
if(isset($fromrequest)){
$freq = $fromrequest->sunit;
} else {
$freq = 0;
}
$get_fromstock = $this->db->select('sunit')->where('ssid',2)->get("Stock");
$fromstock = $get_fromstock->row();
if(isset($fromstock)){
$fstock = $fromstock->sunit;
} else {
$fstock = 0;
}
chang it
$sum = $fromrequest + $fromstock
to
$sum = abs($fromrequest) + abs($fromstock);

SQL delete type double

I am having some issue with sql... Below have a working and not working example. I hard coded them so its easier to see.
$deleteData = $con->prepare("DELETE FROM markers WHERE sid=? AND user_id=? AND lat=? AND lng=?");
$deleteData->bind_param("iidd", $sid, $user_id,$lat,$lng);
$sid= '239';
$user_id = '2';
$lat = '39.724869';
$lng = '-91.400116';
$deleteData -> execute();
Some reason when I attempt to delete using type double in bind_param just doesn't work. Any suggestions? I changed it with or without '' around the lat lng, still doesn't work.
If I change it to below, it deletes just fine.
$deleteData = $con->prepare("DELETE FROM markers WHERE sid=? AND user_id=?);
$deleteData->bind_param("ii", $sid, $user_id);
$sid= '239';
$user_id = '2';
$deleteData -> execute();
First of all you have a syntax error in the second example (missing character ").
Also you did not assigned $sid variable.
Then I have a little bit stupid question. Are you aware, that assign of variables $blog_id, $user_id ... etc. must be before call of method $deleteData->bind_param()?
And also, don't forget that when you are comparing 2 real values, then you should also add some tolerance, so try instead:
$deleteData = $con->prepare("DELETE FROM markers WHERE sid=? AND user_id=? AND ABS(lat - ?) < 0.0000001 AND ABS(lng - ?) < 0.0000001");
Replace $blog_id = '239';with $sid = '239'; since that's the variable name you use in the bind_param() statement.

Problems with converting BSTR to float

I'm trying to convert BSTR to float with:
wcstod(data, NULL)
The problem is that this function works ok if data = 239.78, but i receive them in this format data = 239,78.
CComBSTR data = SysAllocString(L"239,78");
cout<<wcstod(data,NUll)<<endl;
Output of this code is 239.
Anyone could help?
Thank you.
You should use wcstod_l instead and pass the locale you need as the 3rd argument, so the ',' is understood and parsed properly. Something like this:
_locale_t fr = _create_locale(LC_ALL, "fr-FR"); // french locale
CComBSTR data = SysAllocString(L"239,78");
cout<<wcstod_l(data, NULL, fr)<<endl;