MyTetra Share
Делитесь знаниями!
Conversion.Fix Метод
Время создания: 16.03.2020 06:50
Текстовые метки: модуль, mod
Раздел: !Закладки - VBA
Запись: xintrea/mytetra_db_adgaver_new/master/base/1584330623cxmgaa2gv8/text.html на raw.githubusercontent.com

Conversion.Fix Метод

Определение

Пространство имен:

Microsoft.VisualBasic

Сборки:

Microsoft.VisualBasic.dll, Microsoft.VisualBasic.Core.dll

Возвращает целую часть числа.Returns the integer portion of a number.

В этой статье

  1. Определение
  2. Перегрузки
  3. Fix(Decimal)
  4. Fix(Double)
  5. Fix(Int16)
  6. Fix(Int32)
  7. Fix(Int64)
  8. Fix(Object)
  9. Fix(Single)
  10. Применяется к

Перегрузки


Таблица 1

Fix(Decimal)

Возвращает целую часть числа.Returns the integer portion of a number.

Fix(Double)

Возвращает целую часть числа.Returns the integer portion of a number.

Fix(Int16)

Возвращает целую часть числа.Returns the integer portion of a number.

Fix(Int32)

Возвращает целую часть числа.Returns the integer portion of a number.

Fix(Int64)

Возвращает целую часть числа.Returns the integer portion of a number.

Fix(Object)

Возвращает целую часть числа.Returns the integer portion of a number.

Fix(Single)

Возвращает целую часть числа.Returns the integer portion of a number.

Fix(Decimal)

Возвращает целую часть числа.Returns the integer portion of a number.

public:
 static System::Decimal Fix(System::Decimal Number);

C# Копировать

public static decimal Fix (decimal Number);
static member Fix : decimal -> decimal

VB Копировать

Public Function Fix (Number As Decimal) As Decimal

Параметры

Number

Decimal

Обязательное.Required. Число типа Decimal или любое допустимое числовое выражение.A number of type Decimal or any valid numeric expression.

Возвращаемое значение

Decimal

Целая часть числа.The integer portion of a number.

Исключения

ArgumentNullException

Число не указано.Number is not specified.

ArgumentException

Число не является числовым типом.Number is not a numeric type.

Примеры

В этом примере показано, как функции Int и Fix возвращают целые части чисел.This example illustrates how the Int and Fix functions return integer portions of numbers. В случае отрицательного числового аргумента функция Int возвращает первое отрицательное целое число, которое меньше или равно числу. Функция Fix возвращает первое отрицательное целое число, которое больше или равно числу.In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. В следующем примере необходимо указать Option Strict Off Поскольку неявные преобразования из типа Double в тип Integer не допускаются в Option Strict On:The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

VB Копировать

' This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' 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.

Функцию CInt можно использовать для явного преобразования других типов данных в тип Integer с помощью Option Strict Off.You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. Однако CInt округляет до ближайшего целого числа вместо усечения дробной части чисел.However, CInt rounds to the nearest integer instead of truncating the fractional part of numbers. Например:For example:

VB Копировать

MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.

Для выполнения явного преобразования в целое число без округления можно использовать функцию CInt в результате вызова метода Fix или Int.You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. Например:For example:

VB Копировать

MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.

Дополнительные сведения о CIntсм. в разделе функции преобразования типов .For more information on CInt, see Type Conversion Functions .

Комментарии

Функции Int и Fix удаляют дробную часть Number и возвращают результирующее целочисленное значение.Both the Int and Fix functions remove the fractional part of Number and return the resulting integer value.

Различие между функциями Int и Fix заключается в том, что если Number имеет отрицательное значение, Int возвращает первое отрицательное целое число, меньшее или равное Number, тогда как Fix возвращает первое отрицательное целое число, которое больше или равно Number.The difference between Int and Fix functions 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. Например, Int преобразует-8,4 в-9, а Fix преобразует-8,4 в-8.For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) — это эквивалент Sign(number) * Int(Abs(number)).Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

Дополнительно

  • ArgumentNullException
  • Type Conversion FunctionsType Conversion Functions
  • Сводка типов данных (Visual Basic)Data Type Summary (Visual Basic)
  • Сводка по математическим функциямMath Summary
  • Математические функции (Visual Basic)Math Functions (Visual Basic)
  • Сводка по преобразованиюConversion Summary

Fix(Double)

Возвращает целую часть числа.Returns the integer portion of a number.

public:
 static double Fix(double Number);

C# Копировать

public static double Fix (double Number);
static member Fix : double -> double

VB Копировать

Public Function Fix (Number As Double) As Double

Параметры

Number

Double

Обязательное.Required. Число типа Double или любое допустимое числовое выражение.A number of type Double or any valid numeric expression.

Возвращаемое значение

Double

Целая часть числа.The integer portion of a number.

Исключения

ArgumentNullException

Число не указано.Number is not specified.

ArgumentException

Число не является числовым типом.Number is not a numeric type.

Примеры

В этом примере показано, как функции Int и Fix возвращают целые части чисел.This example illustrates how the Int and Fix functions return integer portions of numbers. В случае отрицательного числового аргумента функция Int возвращает первое отрицательное целое число, которое меньше или равно числу. Функция Fix возвращает первое отрицательное целое число, которое больше или равно числу.In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. В следующем примере необходимо указать Option Strict Off Поскольку неявные преобразования из типа Double в тип Integer не допускаются в Option Strict On:The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

VB Копировать

' This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' 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.

Функцию CInt можно использовать для явного преобразования других типов данных в тип Integer с помощью Option Strict Off.You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. Однако CInt округляет до ближайшего целого числа вместо усечения дробной части чисел.However, CInt rounds to the nearest integer instead of truncating the fractional part of numbers. Например:For example:

VB Копировать

MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.

Для выполнения явного преобразования в целое число без округления можно использовать функцию CInt в результате вызова метода Fix или Int.You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. Например:For example:

VB Копировать

MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.

Дополнительные сведения о CIntсм. в разделе функции преобразования типов .For more information on CInt, see Type Conversion Functions .

Комментарии

Функции Int и Fix удаляют дробную часть Number и возвращают результирующее целочисленное значение.Both the Int and Fix functions remove the fractional part of Number and return the resulting integer value.

Различие между функциями Int и Fix заключается в том, что если Number имеет отрицательное значение, Int возвращает первое отрицательное целое число, меньшее или равное Number, тогда как Fix возвращает первое отрицательное целое число, которое больше или равно Number.The difference between Int and Fix functions 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. Например, Int преобразует-8,4 в-9, а Fix преобразует-8,4 в-8.For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) — это эквивалент Sign(number) * Int(Abs(number)).Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

Начиная с Visual Basic 15,8, производительность преобразования Doubleв целое число оптимизирована, если передать значение, возвращаемое методом Fix, в любую из целочисленных функций преобразования или значение Double, возвращаемое Fix, неявно преобразуется в целое число с параметром Option , равным Off.Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the Fix method to the any of the integral conversion functions , or if the Double value returned by Fix is implicitly converted to an integer with Option Strict set to Off. Эта оптимизация позволяет коду выполняться быстрее — до двух раз быстрее для кода, который выполняет большое количество преобразований в целочисленные типы.This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. В следующем примере показано такое Оптимизированное преобразование:The following example illustrates such an optimized conversion:

VB Копировать

Dim d As Double = 173.7619
Dim i1 As Integer = CInt(Fix(d))           ' Result: 173

Дополнительно

  • ArgumentNullException
  • Type Conversion FunctionsType Conversion Functions
  • Сводка типов данных (Visual Basic)Data Type Summary (Visual Basic)
  • Сводка по математическим функциямMath Summary
  • Математические функции (Visual Basic)Math Functions (Visual Basic)
  • Сводка по преобразованиюConversion Summary

Fix(Int16)

Возвращает целую часть числа.Returns the integer portion of a number.

public:
 static short Fix(short Number);

C# Копировать

public static short Fix (short Number);
static member Fix : int16 -> int16

VB Копировать

Public Function Fix (Number As Short) As Short

Параметры

Number

Int16

Обязательное.Required. Число типа Short или любое допустимое числовое выражение.A number of type Short or any valid numeric expression.

Возвращаемое значение

Int16

Целая часть числа.The integer portion of a number.

Исключения

ArgumentNullException

Число не указано.Number is not specified.

ArgumentException

Число не является числовым типом.Number is not a numeric type.

Примеры

В этом примере показано, как функции Int и Fix возвращают целые части чисел.This example illustrates how the Int and Fix functions return integer portions of numbers. В случае отрицательного числового аргумента функция Int возвращает первое отрицательное целое число, которое меньше или равно числу. Функция Fix возвращает первое отрицательное целое число, которое больше или равно числу.In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. В следующем примере необходимо указать Option Strict Off Поскольку неявные преобразования из типа Double в тип Integer не допускаются в Option Strict On:The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

VB Копировать

' This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' 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.

Функцию CInt можно использовать для явного преобразования других типов данных в тип Integer с помощью Option Strict Off.You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. Однако CInt округляет до ближайшего целого числа вместо усечения дробной части чисел.However, CInt rounds to the nearest integer instead of truncating the fractional part of numbers. Например:For example:

VB Копировать

MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.

Для выполнения явного преобразования в целое число без округления можно использовать функцию CInt в результате вызова метода Fix или Int.You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. Например:For example:

VB Копировать

MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.

Дополнительные сведения о CIntсм. в разделе функции преобразования типов .For more information on CInt, see Type Conversion Functions .

Комментарии

Функции Int и Fix удаляют дробную часть Number и возвращают результирующее целочисленное значение.Both the Int and Fix functions remove the fractional part of Number and return the resulting integer value.

Различие между функциями Int и Fix заключается в том, что если Number имеет отрицательное значение, Int возвращает первое отрицательное целое число, меньшее или равное Number, тогда как Fix возвращает первое отрицательное целое число, которое больше или равно Number.The difference between Int and Fix functions 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. Например, Int преобразует-8,4 в-9, а Fix преобразует-8,4 в-8.For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) — это эквивалент Sign(number) * Int(Abs(number)).Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

Дополнительно

  • ArgumentNullException
  • Type Conversion FunctionsType Conversion Functions
  • Сводка типов данных (Visual Basic)Data Type Summary (Visual Basic)
  • Сводка по математическим функциямMath Summary
  • Математические функции (Visual Basic)Math Functions (Visual Basic)
  • Сводка по преобразованиюConversion Summary

Fix(Int32)

Возвращает целую часть числа.Returns the integer portion of a number.

public:
 static int Fix(int Number);

C# Копировать

public static int Fix (int Number);
static member Fix : int -> int

VB Копировать

Public Function Fix (Number As Integer) As Integer

Параметры

Number

Int32

Обязательное.Required. Число типа Integer или любое допустимое числовое выражение.A number of type Integer or any valid numeric expression.

Возвращаемое значение

Int32

Целая часть числа.The integer portion of a number.

Исключения

ArgumentNullException

Число не указано.Number is not specified.

ArgumentException

Число не является числовым типом.Number is not a numeric type.

Примеры

В этом примере показано, как функции Int и Fix возвращают целые части чисел.This example illustrates how the Int and Fix functions return integer portions of numbers. В случае отрицательного числового аргумента функция Int возвращает первое отрицательное целое число, которое меньше или равно числу. Функция Fix возвращает первое отрицательное целое число, которое больше или равно числу.In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. В следующем примере необходимо указать Option Strict Off Поскольку неявные преобразования из типа Double в тип Integer не допускаются в Option Strict On:The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

VB Копировать

' This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' 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.

Функцию CInt можно использовать для явного преобразования других типов данных в тип Integer с помощью Option Strict Off.You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. Однако CInt округляет до ближайшего целого числа вместо усечения дробной части чисел.However, CInt rounds to the nearest integer instead of truncating the fractional part of numbers. Например:For example:

VB Копировать

MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.

Для выполнения явного преобразования в целое число без округления можно использовать функцию CInt в результате вызова метода Fix или Int.You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. Например:For example:

VB Копировать

MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.

Дополнительные сведения о CIntсм. в разделе функции преобразования типов .For more information on CInt, see Type Conversion Functions .

Комментарии

Функции Int и Fix удаляют дробную часть Number и возвращают результирующее целочисленное значение.Both the Int and Fix functions remove the fractional part of Number and return the resulting integer value.

Различие между функциями Int и Fix заключается в том, что если Number имеет отрицательное значение, Int возвращает первое отрицательное целое число, меньшее или равное Number, тогда как Fix возвращает первое отрицательное целое число, которое больше или равно Number.The difference between Int and Fix functions 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. Например, Int преобразует-8,4 в-9, а Fix преобразует-8,4 в-8.For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) — это эквивалент Sign(number) * Int(Abs(number)).Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

Дополнительно

  • ArgumentNullException
  • Type Conversion FunctionsType Conversion Functions
  • Сводка типов данных (Visual Basic)Data Type Summary (Visual Basic)
  • Сводка по математическим функциямMath Summary
  • Математические функции (Visual Basic)Math Functions (Visual Basic)
  • Сводка по преобразованиюConversion Summary

Fix(Int64)

Возвращает целую часть числа.Returns the integer portion of a number.

public:
 static long Fix(long Number);

C# Копировать

public static long Fix (long Number);
static member Fix : int64 -> int64

VB Копировать

Public Function Fix (Number As Long) As Long

Параметры

Number

Int64

Обязательное.Required. Число типа Long или любое допустимое числовое выражение.A number of type Long or any valid numeric expression.

Возвращаемое значение

Int64

Целая часть числа.The integer portion of a number.

Исключения

ArgumentNullException

Число не указано.Number is not specified.

ArgumentException

Число не является числовым типом.Number is not a numeric type.

Примеры

В этом примере показано, как функции Int и Fix возвращают целые части чисел.This example illustrates how the Int and Fix functions return integer portions of numbers. В случае отрицательного числового аргумента функция Int возвращает первое отрицательное целое число, которое меньше или равно числу. Функция Fix возвращает первое отрицательное целое число, которое больше или равно числу.In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. В следующем примере необходимо указать Option Strict Off Поскольку неявные преобразования из типа Double в тип Integer не допускаются в Option Strict On:The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

VB Копировать

' This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' 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.

Функцию CInt можно использовать для явного преобразования других типов данных в тип Integer с помощью Option Strict Off.You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. Однако CInt округляет до ближайшего целого числа вместо усечения дробной части чисел.However, CInt rounds to the nearest integer instead of truncating the fractional part of numbers. Например:For example:

VB Копировать

MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.

Для выполнения явного преобразования в целое число без округления можно использовать функцию CInt в результате вызова метода Fix или Int.You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. Например:For example:

VB Копировать

MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.

Дополнительные сведения о CIntсм. в разделе функции преобразования типов .For more information on CInt, see Type Conversion Functions .

Комментарии

Функции Int и Fix удаляют дробную часть Number и возвращают результирующее целочисленное значение.Both the Int and Fix functions remove the fractional part of Number and return the resulting integer value.

Различие между функциями Int и Fix заключается в том, что если Number имеет отрицательное значение, Int возвращает первое отрицательное целое число, меньшее или равное Number, тогда как Fix возвращает первое отрицательное целое число, которое больше или равно Number.The difference between Int and Fix functions 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. Например, Int преобразует-8,4 в-9, а Fix преобразует-8,4 в-8.For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) — это эквивалент Sign(number) * Int(Abs(number)).Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

Дополнительно

  • ArgumentNullException
  • Type Conversion FunctionsType Conversion Functions
  • Сводка типов данных (Visual Basic)Data Type Summary (Visual Basic)
  • Сводка по математическим функциямMath Summary
  • Математические функции (Visual Basic)Math Functions (Visual Basic)
  • Сводка по преобразованиюConversion Summary

Fix(Object)

Возвращает целую часть числа.Returns the integer portion of a number.

public:
 static System::Object ^ Fix(System::Object ^ Number);

C# Копировать

public static object Fix (object Number);
static member Fix : obj -> obj

VB Копировать

Public Function Fix (Number As Object) As Object

Параметры

Number

Object

Обязательное.Required. Число типа Object или любое допустимое числовое выражение.A number of type Object or any valid numeric expression. Если параметр Number имеет значение Nothing, то возвращается значение Nothing.If Number contains Nothing, Nothing is returned.

Возвращаемое значение

Object

Целая часть числа.The integer portion of a number.

Исключения

ArgumentNullException

Число не указано.Number is not specified.

ArgumentException

Число не является числовым типом.Number is not a numeric type.

Примеры

В этом примере показано, как функции Int и Fix возвращают целые части чисел.This example illustrates how the Int and Fix functions return integer portions of numbers. В случае отрицательного числового аргумента функция Int возвращает первое отрицательное целое число, которое меньше или равно числу. Функция Fix возвращает первое отрицательное целое число, которое больше или равно числу.In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. В следующем примере необходимо указать Option Strict Off Поскольку неявные преобразования из типа Double в тип Integer не допускаются в Option Strict On:The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

VB Копировать

' This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' 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.

Функцию CInt можно использовать для явного преобразования других типов данных в тип Integer с помощью Option Strict Off.You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. Однако CInt округляет до ближайшего целого числа вместо усечения дробной части чисел.However, CInt rounds to the nearest integer instead of truncating the fractional part of numbers. Например:For example:

VB Копировать

MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.

Для выполнения явного преобразования в целое число без округления можно использовать функцию CInt в результате вызова метода Fix или Int.You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. Например:For example:

VB Копировать

MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.

Дополнительные сведения о CIntсм. в разделе функции преобразования типов .For more information on CInt, see Type Conversion Functions .

Комментарии

Функции Int и Fix удаляют дробную часть Number и возвращают результирующее целочисленное значение.Both the Int and Fix functions remove the fractional part of Number and return the resulting integer value.

Различие между функциями Int и Fix заключается в том, что если Number имеет отрицательное значение, Int возвращает первое отрицательное целое число, меньшее или равное Number, тогда как Fix возвращает первое отрицательное целое число, которое больше или равно Number.The difference between Int and Fix functions 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. Например, Int преобразует-8,4 в-9, а Fix преобразует-8,4 в-8.For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) — это эквивалент Sign(number) * Int(Abs(number)).Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

Начиная с Visual Basic 15,8, если аргумент Number является объектом, тип среды выполнения которого — Double или Single, производительность преобразования с плавающей запятой в целое число оптимизирована, если передать значение, возвращаемое методом Fix, в любую из целочисленных функций преобразования или значение, возвращаемое Fix, автоматически преобразуется в целое число с параметром Option строго со значением OFF.Starting with Visual Basic 15.8, if the Number argument is an object whose runtime type is Double or Single, the performance of floating-point-to-integer conversion is optimized if you pass the value returned by the Fix method to the any of the integral conversion functions , or if the value returned by Fix is automatically converted to an integer with Option Strict set to Off. Эта оптимизация позволяет коду выполняться быстрее — до двух раз быстрее для кода, который выполняет большое количество преобразований в целочисленные типы.This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. Например:For example:

VB Копировать

Dim d As Object = 173.7619
Dim i1 As Integer = CInt(Fix(d))           ' Result: 173
Dim s As Object = 173.7619F
Dim i2 As Integer = CInt(Fix(s))           ' Result: 173

Дополнительно

  • ArgumentNullException
  • Type Conversion FunctionsType Conversion Functions
  • Сводка типов данных (Visual Basic)Data Type Summary (Visual Basic)
  • Сводка по математическим функциямMath Summary
  • Математические функции (Visual Basic)Math Functions (Visual Basic)
  • Сводка по преобразованиюConversion Summary

Fix(Single)

Возвращает целую часть числа.Returns the integer portion of a number.

public:
 static float Fix(float Number);

C# Копировать

public static float Fix (float Number);
static member Fix : single -> single

VB Копировать

Public Function Fix (Number As Single) As Single

Параметры

Number

Single

Обязательное.Required. Число типа Single или любое допустимое числовое выражение.A number of type Single or any valid numeric expression.

Возвращаемое значение

Single

Целая часть числа.The integer portion of a number.

Исключения

ArgumentNullException

Число не указано.Number is not specified.

ArgumentException

Число не является числовым типом.Number is not a numeric type.

Примеры

В этом примере показано, как функции Int и Fix возвращают целые части чисел.This example illustrates how the Int and Fix functions return integer portions of numbers. В случае отрицательного числового аргумента функция Int возвращает первое отрицательное целое число, которое меньше или равно числу. Функция Fix возвращает первое отрицательное целое число, которое больше или равно числу.In the case of a negative number argument, the Int function returns the first negative integer less than or equal to the number; the Fix function returns the first negative integer greater than or equal to the number. В следующем примере необходимо указать Option Strict Off Поскольку неявные преобразования из типа Double в тип Integer не допускаются в Option Strict On:The following example requires you to specify Option Strict Off because implicit conversions from type Double to type Integer are not allowed under Option Strict On:

VB Копировать

' This code requires Option Strict Off
Dim MyNumber As Integer
MyNumber = Int(99.8)   ' Returns 99.
MyNumber = Fix(99.8)   ' 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.

Функцию CInt можно использовать для явного преобразования других типов данных в тип Integer с помощью Option Strict Off.You can use the CInt function to explicitly convert other data types to type Integer with Option Strict Off. Однако CInt округляет до ближайшего целого числа вместо усечения дробной части чисел.However, CInt rounds to the nearest integer instead of truncating the fractional part of numbers. Например:For example:

VB Копировать

MyNumber = CInt(99.8)    ' Returns 100.
MyNumber = CInt(-99.8)   ' Returns -100.
MyNumber = CInt(-99.2)   ' Returns -99.

Для выполнения явного преобразования в целое число без округления можно использовать функцию CInt в результате вызова метода Fix или Int.You can use the CInt function on the result of a call to Fix or Int to perform explicit conversion to integer without rounding. Например:For example:

VB Копировать

MyNumber = CInt(Fix(99.8))   ' Returns 99.
MyNumber = CInt(Int(99.8))   ' Returns 99.

Дополнительные сведения о CIntсм. в разделе функции преобразования типов .For more information on CInt, see Type Conversion Functions .

Комментарии

Функции Int и Fix удаляют дробную часть Number и возвращают результирующее целочисленное значение.Both the Int and Fix functions remove the fractional part of Number and return the resulting integer value.

Различие между функциями Int и Fix заключается в том, что если Number имеет отрицательное значение, Int возвращает первое отрицательное целое число, меньшее или равное Number, тогда как Fix возвращает первое отрицательное целое число, которое больше или равно Number.The difference between Int and Fix functions 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. Например, Int преобразует-8,4 в-9, а Fix преобразует-8,4 в-8.For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) — это эквивалент Sign(number) * Int(Abs(number)).Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

Начиная с Visual Basic 15,8, производительность преобразования Singleв целое число оптимизирована, если передать значение, возвращаемое методом Fix, в любую из целочисленных функций преобразования или значение Single, возвращаемое Fix, автоматически преобразуется в целое число с параметром Option-on Off.Starting with Visual Basic 15.8, the performance of Single-to-integer conversion is optimized if you pass the value returned by the Fix method to the any of the integral conversion functions , or if the Single value returned by Fix is automatically converted to an integer with Option Strict set to Off. Эта оптимизация позволяет коду выполняться быстрее — до двух раз быстрее для кода, который выполняет большое количество преобразований в целочисленные типы.This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. В следующем примере показано такое Оптимизированное преобразование:The following example illustrates such an optimized conversion:

VB Копировать

Dim s As Single = 173.7619
Dim i2 As Integer = CInt(Fix(s))           ' Result: 173

Дополнительно

  • ArgumentNullException
  • Type Conversion FunctionsType Conversion Functions
  • Сводка типов данных (Visual Basic)Data Type Summary (Visual Basic)
  • Сводка по математическим функциямMath Summary
  • Математические функции (Visual Basic)Math Functions (Visual Basic)
  • Сводка по преобразованиюConversion Summary

Применяется к

.NET Core

3.1 3.0

.NET Framework

4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования