Forum > General
TryStrToFloat
BubikolRamios:
Hmm, no message. Note there is nothing after '.'.
I assume it thinks strtofloat('0.') is 0. How to check then if string or decimal ?
--- 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";}};} ---var fs: TFormatSettings; x: Float;begin x := NaN; fs := FormatSettings; fs.DecimalSeparator := '.'; if not TryStrToFloat('0.',x, fs)then begin showmessage('foo'); end;
paweld:
if the TryStrToFloat function returns TRUE, it means that the string was successfully converted to a number, and if FALSE, the conversion failed.
--- 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";}};} ---var fs: TFormatSettings; x: Double;begin fs.DecimalSeparator := '.'; if TryStrToFloat('0.', x, fs) then ShowMessage('It''s float: ' + FloatToStr(x)) else showmessage('It'' string');end;
Thaddy:
Should it not be '0.0';?
I mean it is not called a separator for nothing: it expects two decimal values either side of the dot.
BubikolRamios:
--- Quote from: Thaddy on September 09, 2024, 06:54:07 am ---Should it not be '0.0';?
I mean it is not called a separator for nothing: it expects two decimal values either side of the dot.
--- End quote ---
Checking that OnKeyUp on TEdit control... Press backspace on something like '0.2'
BubikolRamios:
test:
--- 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";}};} ---showmessage(FloatToStr(StrToFloat('0.'))); //--> 0showmessage(FloatToStr(StrToFloat('01')));//--> 1
Not very logical.
Navigation
[0] Message Index
[#] Next page