PDA

View Full Version : معادل چند تابع VB در Delphi



Delphi KDE
چهارشنبه 04 آذر 1383, 02:56 صبح
سلام دوستان
من یک برنامه VB دارم که میخواهم اون را به معادل دلفی تبدیل کنم
مشکل من با این چند تابع زیر است
لطفا معادل اونها را در دلفی بنویسید
در ضمن این توابع در محاسبات دقیقی به کار میروند ولازم است معادل اونها در دلفی دقیقا دقیقا همان خروجی را در دلفی بدهد


int()
fix()
clng()
ceil()

حامد مصافی
چهارشنبه 04 آذر 1383, 11:44 صبح
معادل دو تابع اول اینه


int()
round()


clng()
این تابع بسته به این که از کدوم نوع بخوای تبدیل کنی توابع مختلفی داره

ceil()
میشه بگی این چیه؟

Delphi KDE
پنج شنبه 05 آذر 1383, 02:27 صبح
تا انجایی که من میدانم در دلفی تابع int فقط قسمت صحیح عدد را برمیگرداند
و تابع round() در وی بی هم وجو دارد پس اگر اشتباه نکنم تابع روند ویبی معادل تابع روند در دلفی است
در مورد Ceil() بعد متوجه شدم توسط کاربر ایجاد شده
در ضمن اگر لطف کنید معادل تابع زیر را هم بنویسید ممنون میشم

Sgn()
****************************ً()Round************* ***********//
The Round function performs round to even, which is different from round to larger. The return value is the number closest to the value of expression, with the appropriate number of decimal places. If expression is exactly halfway between two possible rounded values, the function returns the possible rounded value whose rightmost digit is an even number. (In a round to larger function, a number that is halfway between two possible rounded values is always rounded to the larger number.)

Note Round to even is a statistically more accurate rounding algorithm than round to larger.
Example
The following example uses the Round function to round a number to two decimal places


Dim MyVar, pi
pi = 3.14159
MyVar = Round(pi, 2) ' MyVar contains 3.14.
This example demonstrates how rounding to even works

Dim var1, var2, var3, var4, var5
var1 = Round(1.5) ' var1 contains 2
var2 = Round(2.5) ' var2 contains 2
var3 = Round(3.5) ' var3 contains 4
var4 = Round(0.985, 2) ' var4 contains 0.98
var5 = Round(0.995, 2) ' var5 contains 1.00

The number argument can be any valid numeric expression. If number contains Null, Null is returned.
*************************()fix() and int********************//
Both Int and Fix remove the fractional part of number and return the resulting integer value.

The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) is equivalent to


Sgn(number) * Int(Abs(number))
The following examples illustrate how the Int and Fix functions return integer portions of numbers

MyNumber = Int(99.8) ' Returns 99.
MyNumber = Fix(99.2) ' Returns 99.
MyNumber = Int(-99.8) ' Returns -100.
MyNumber = Fix(-99.8) ' Returns -99.
MyNumber = Int(-99.2) ' Returns -100.
MyNumber = Fix(-99.2) ' Returns -99.
****************************()Clng**************** *********//
In general, you can document your code using the subtype conversion functions to show that the result of some operation should be expressed as a particular data type rather than the default data type. For example, use CInt or CLng to force integer arithmetic in cases where currency, single-precision, or double-precision arithmetic normally would occur.

Use the CLng function to provide internationally aware conversions from any other data type to a Long subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators.

If expression lies outside the acceptable range for the Long subtype, an error occurs.

The following example uses the CLng function to convert a value to a Long
In general, you can document your code using the subtype conversion functions to show that the result of some operation should be expressed as a particular data type rather than the default data type. For example, use CInt or CLng to force integer arithmetic in cases where currency, single-precision, or double-precision arithmetic normally would occur.

Use the CLng function to provide internationally aware conversions from any other data type to a Long subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators.

If expression lies outside the acceptable range for the Long subtype, an error occurs.

The following example uses the CLng function to convert a value to a Long


Dim MyVal1, MyVal2, MyLong1, MyLong2
MyVal1 = 25427.45: MyVal2 = 25427.55 ' MyVal1, MyVal2 are Doubles.
MyLong1 = CLng(MyVal1) ' MyLong1 contains 25427.
MyLong2 = CLng(MyVal2) ' MyLong2 contains 25428.
Note CLng differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CLng function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.

اگر لطف کنید معادل دقیق توابع پست قبلی را برام بنویسید ممنون میشم

حامد مصافی
سه شنبه 10 آذر 1383, 13:32 عصر
ببخشید یه مدتی نبودم
معادل round در دلفی roundto است
من معادل sgn در دلفی رو نمیدونم ولی این تابع به ازای اعداد مثبت 1 ، به ازای اعداد منفی -1 و به ازای صفر خود 0 را بر می گرداند . پس می توانیم آن را به این صورت بازنویسی کنیم


ّFunction sgn ( n : real ) : Integer
Var
tn : integer ;
BEGIN
if ( n < 0 ) then tn := -1;
if ( n > 0 ) then tn := 1;
if ( n = 0 ) then tn := 0;
sgn := tn;
END

Delphi KDE
پنج شنبه 12 آذر 1383, 02:16 صبح
ممنون دوست عزیز ولی خودم معادل همشون رو در دلفی پیدا کردم

sgn() = Sign()
و برای توابع دیگر

Floor(),Ceil(),Trunc()

mohsengrisly
پنج شنبه 12 آذر 1383, 10:26 صبح
بسیار جالب بود
من هم استفاده کردم وممنونم :موفق: