Share via


DataFunctions.Float Method (PIA)

Use this method to convert a number stored in a double to a string representation of that number, based on the default or specified locale.

Definition

[Visual Basic .NET]

Imports Microsoft.CommerceServer.Interop
…

Public Function Float(fNumber As Double,
 OptionalvtLocale As Object
 Optional vtNoRound As Object,
 Optional vtTrimTrailingZerosAs Object) As Object

[C#]

using Microsoft.CommerceServer.Interop;
…
public object Float(doublefNumber,
 objectvtLocaleobjectvtNoRound
objectvtTrimTrailingZeros);

Parameters

[Visual Basic .NET]

  • fNumber
    A Double that contains the floating-point number to convert.
  • vtLocale
    An Object that specifies the locale to use to convert the floating-point number to a string. If this parameter is not specified, the value of the Locale property of the DataFunctions object is used.
  • VtNoRound
    An Object that determines whether the number will be rounded.
  • VtTrimTrailingZeros
    An Object that determines whether trailing zeros will be cropped.

[C#]

  • fNumber
    A double (8-byte floating point number) that contains the floating-point number to convert.
  • vtLocale
    An object that specifies the locale to use to convert the floating-point number to a string. If you want the value of the Locale property of the DataFunctions object to be used, pass Type.Missing for this parameter.
  • VtNoRound
    An Object that determines whether the number will be rounded.
  • VtTrimTrailingZeros
    An Object that determines whether trailing zeros will be cropped.

Return Values

The value returned from the Float method is intended for display purposes only, and not in any calculations.

[Visual Basic .NET] If this method completes successfully, it returns a string Object that contains the string representation of the specified floating-point number; otherwise, Null is returned.

[C#] This method returns an object containing the string representation of the specified floating point number.

Exceptions

This method may throw one of many mapped exceptions or an exception of type COMException. See Standard COM Errors for additional details.

Remarks

The value returned from the Float method is intended for display purposes only, and not in any calculations.

The string representation of a floating pointer number (of type VT_R4) returned by the Float method can contain additional trailing digits that may not have been specified as part of the original user input value. For example, 2.23 is formatted as “2.23000001907349”, and 2.23456 is formatted as “2.23456001281738”.

The reason for the change in formatting is that when a float value is passed into this function, it is automatically cast to a double value by the language runtime libraries (because this method expects a double-typed argument). It is during this cast operation that the trailing digits get added to the passed in value. Since the Float method formats the entire input value into a string, the resulting string value contains the additional trailing digits.

The workaround for client applications is to invoke this method with the VtNoRound argument set to False.

Example

[Visual Basic .NET]

Dim Result As Object
Dim Amount As Double
Amount = 12000
DataFunctions df = New DataFunctions()
' Set Locale to USA
df.Locale = 1033
myInputFloat = 100.00010
Result = df.Float(myInputFloat)
Response.Write("USA, No Rounding, With Trailing: " & Result & "<P>")
Result = df.Float(myInputFloat)
Response.Write("USA, No Rounding, Trim Trailing: " & Result & "<P>")
Result = df.Float(myInputFloat)
Response.Write("USA, Rounding, With Trailing: " & Result & "<P>")
Result = df.Float(myInputFloat)
Response.Write("USA, Rounding, Trim Trailing: " & Result & "<P>")

[C#]

No example available.

Requirements

Namespace: Microsoft.CommerceServer.Interop

Platforms: Windows 2000, Windows Server 2003

Assembly: mscsasphelplib (in mscsasphelplib.dll)

See Also

DataFunctions Class

DataFunctions.Locale

DataFunctions.ValidateFloat

DataFunctions.ConvertFloatString

Copyright © 2005 Microsoft Corporation.
All rights reserved.