次の方法で共有


XmlConvert.ToString メソッド (Double)

DoubleString に変換します。

Overloads Public Shared Function ToString( _
   ByVal value As Double _) As String
[C#]
public static string ToString(doublevalue);
[C++]
public: static String* ToString(doublevalue);
[JScript]
public static function ToString(
   value : double) : String;

パラメータ

  • value
    変換する値。

戻り値

Double の文字列形式。

解説

value が Double.PositiveInfinity または Double.NegativeInfinity の場合、このメソッドはそれぞれ文字列 INF または文字列 -INF を返します。

使用例

[Visual Basic, C#, C++] データ型を文字列に変換してから、情報をコンソールに書き込む例を次に示します。

 
Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    'Define the order data.  They will be converted to string
    'before being written out.
    Dim custID as Int16 = 32632
    Dim orderID as String = "367A54"
    Dim orderDate as DateTime 
    orderDate = DateTime.Now
    Dim price as Double = 19.95

    'Create a writer that outputs to the console.
    Dim writer as XmlTextWriter = new XmlTextWriter (Console.Out)
    'Use indenting for readability
    writer.Formatting = Formatting.Indented
    
    'Write an element (this one is the root)
    writer.WriteStartElement("order")

    'Write the order date.
    writer.WriteAttributeString("date", XmlConvert.ToString(orderDate, "yyyy-MM-dd"))

    'Write the order time.
    writer.WriteAttributeString("time", XmlConvert.ToString(orderDate, "HH:mm:ss"))
    
    'Write the order data.
    writer.WriteElementString("orderID", orderID)
    writer.WriteElementString("custID", XmlConvert.ToString(custID))
    writer.WriteElementString("price", XmlConvert.ToString(price))

    'Write the close tag for the root element
    writer.WriteEndElement()
             

    'Write the XML and close the writer
    writer.Flush()
    writer.Close()  

  end sub
end class

[C#] 
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    //Define the order data.  They will be converted to string 
    //before being written out.
    Int16 custID = 32632;
    String orderID = "367A54";
    DateTime orderDate = new DateTime();
    orderDate = DateTime.Now;
    Double price = 19.95;

    //Create a writer that outputs to the console.
    XmlTextWriter writer = new XmlTextWriter (Console.Out);
    writer.Formatting = Formatting.Indented;

    //Write an element (this one is the root)
    writer.WriteStartElement("order");

    //Write the order date.
    writer.WriteAttributeString("date", XmlConvert.ToString(orderDate, "yyyy-MM-dd"));

    //Write the order time.
    writer.WriteAttributeString("time", XmlConvert.ToString(orderDate, "HH:mm:ss"));
    
    //Write the order data.
    writer.WriteElementString("orderID", orderID);
    writer.WriteElementString("custID", XmlConvert.ToString(custID));
    writer.WriteElementString("price", XmlConvert.ToString(price));

    //Write the close tag for the root element
    writer.WriteEndElement();
             
    //Write the XML and close the writer
    writer.Close();  

  }

}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
    //Define the order data.  They will be converted to string 
    //before being written out.
    Int16 custID = 32632;
    String* orderID = S"367A54";
    DateTime orderDate = DateTime::Now;
    Double price = 19.95;

    //Create a writer that outputs to the console.
    XmlTextWriter* writer = new XmlTextWriter (Console::Out);
    writer->Formatting = Formatting::Indented;

    //Write an element (this one is the root)
    writer->WriteStartElement(S"order");

    //Write the order date.
    writer->WriteAttributeString(S"date", XmlConvert::ToString(orderDate, S"yyyy-MM-dd"));

    //Write the order time.
    writer->WriteAttributeString(S"time", XmlConvert::ToString(orderDate, S"HH:mm:ss"));
    
    //Write the order data.
    writer->WriteElementString(S"orderID", orderID);
    writer->WriteElementString(S"custID", XmlConvert::ToString(custID));
    writer->WriteElementString(S"price", XmlConvert::ToString(price));

    //Write the close tag for the root element
    writer->WriteEndElement();
             
    //Write the XML and close the writer
    writer->Close();  
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

XmlConvert クラス | XmlConvert メンバ | System.Xml 名前空間 | XmlConvert.ToString オーバーロードの一覧 | PositiveInfinity | NegativeInfinity