Forum > General
tostring is working properly ?
Paolo:
Hello,
incidentally I see that the code below compile with double variabile but not with real variabile, is this bheaviour the expected one ? (really I do not make use of real type, but I noted this), doesn't real is an alias of double ?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button5Click(Sender: TObject);var a : real; b : double; c : string;begin c:=a.tostring; <--- it does not compile c:=b.tostring; <--- it compilesend;
laz 2.2.2, fpc 3.2.2 win10
mirce.vladimirov:
I dont realy know about this, I am using :
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---c:=floattostr(a) ;c:=floattostr(b);c:=inttostr(some_integer_variable);
There are also oposite strtoint() and strtofloat()
PascalDragon:
--- Quote from: Paolo on March 17, 2023, 03:51:29 pm ---incidentally I see that the code below compile with double variabile but not with real variabile, is this bheaviour the expected one ? (really I do not make use of real type, but I noted this), doesn't real is an alias of double ?
--- End quote ---
Real is a unique alias of Double (type Real = type Double vs. type Real = Double) and thus type helpers for Double are not in scope for Real variables. So yes, this is expected behaviour.
Paolo:
thanks for the explaination. (It is the expected behaviour according to type definition, but is it the desired behaviour ? :))
We can say that "tostring" is less portable than "/floattostr/flrotstrF/etc.." family. Having code with double and a lot of "tostring" if the type is changed to real casues a lot of compiler errors.
(But again it is not a real isssue for me, since I am using only double type since long time ago...)
dsiders:
--- Quote from: Paolo on March 17, 2023, 04:39:03 pm ---We can say that "tostring" is less portable than "/floattostr/flrotstrF/etc.." family. Having code with double and a lot of "tostring" if the type is changed to real casues a lot of compiler errors.
--- End quote ---
But Real.ToString is exactly as portable as the StrtoReal and RealToString routines. Because they don't exist either.
Navigation
[0] Message Index
[#] Next page