2009年8月9日日曜日

fri2decimal

var yahoo
fri_dec: double; AION NAVI
function csubstr(substr: string; str: string): integer;
var
i, j: integer;
begin
j := 0;
for i := 1 to length(str) do
if str[i] = substr then j := j + 1;
result := j;
end;

function onlydecimal(str_fri: string): double;
begin
if csubstr('.', str_fri) <> 1 then
str_fri := StringReplace(str_fri, '.', '', [rfReplaceAll]);
result := strtofloat(str_fri);
end;

function onlyspace(str_fri: string): double;
begin

str_fri := StringReplace(str_fri, ' ', '', [rfReplaceAll]);
result := strtofloat(str_fri);
end;

function onlyxg(str_fri: string): double;
begin

if (pos('/', str_fri) = 1) or (pos('/', str_fri) = length(str_fri)) or (csubstr('/', str_fri) <> 1) then
begin
str_fri := StringReplace(str_fri, '/', '', [rfReplaceAll]);
result := strtofloat(str_fri);
end
else
begin
strs := TStringList.Create;
strs.Delimiter := '/';
strs.DelimitedText := str_fri;
if strtofloat(strs[1]) = 0 then
result := strtofloat(strs[0])
else
result := roundto(strtofloat(strs[0]) / strtofloat(strs[1]), -5);
strs.Free;
end;
end;

function spacexg(str_fri: string): double;
begin
if (pos('/', str_fri) = 1) or (pos('/', str_fri) = length(str_fri)) or (csubstr('/', str_fri) <> 1) then /
begin
str_fri := StringReplace(str_fri, '/', '', [rfReplaceAll]);
result := onlyspace(str_fri);
end
else if (pos('/', str_fri) < pos(' ', str_fri)) or (csubstr(' ', str_fri) <> 1) then
begin
str_fri := StringReplace(str_fri, ' ', '', [rfReplaceAll]);
result := onlyxg(str_fri);
end
else
begin
strs := TStringList.Create;
strs.Delimiter := ' ';
strs.DelimitedText := str_fri;
result := strtofloat(strs[0]) + onlyxg(strs[1]);
end;
end;
begin
result := 0;

if (pos(' ', fri) = 0) and (pos('.', fri) = 0) and (pos('/', fri) = 0) then
result := strtofloat(fri);

if (pos(' ', fri) = 0) and (pos('.', fri) <> 0) and (pos('/', fri) = 0) then
result := onlydecimal(fri);

if (pos(' ', fri) <> 0) and (pos('.', fri) = 0) and (pos('/', fri) = 0) then
result := onlyspace(fri);

if (pos(' ', fri) = 0) and (pos('.', fri) = 0) and (pos('/', fri) <> 0) then
result := onlyxg(fri);
if (pos(' ', fri) <> 0) and (pos('.', fri) <> 0) and (pos('/', fri) = 0) then
begin
fri := StringReplace(fri, ' ', '', [rfReplaceAll]);
result := onlydecimal(fri);
end;

if (pos(' ', fri) = 0) and (pos('.', fri) <> 0) and (pos('/', fri) <> 0) then
begin
fri := StringReplace(fri, '.', '', [rfReplaceAll]);
result := onlyxg(fri);
end;


if (pos(' ', fri) <> 0) and (pos('.', fri) = 0) and (pos('/', fri) <> 0) then
result := spacexg(fri);

if (pos(' ', fri) <> 0) and (pos('.', fri) <> 0) and (pos('/', fri) <> 0) then
begin
fri := StringReplace(fri, '.', '', [rfReplaceAll]);
result := spacexg(fri);
end;
end;

0 件のコメント:

コメントを投稿