程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> NativeXml (11):浮點數的有效位數

NativeXml (11):浮點數的有效位數

編輯:Delphi

uses NativeXML; 
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  xml: TNativeXML; 
  fVal: Double; 
begin 
  fVal := 123.456789; 
 
  xml := TNativeXML.CreateName('List'); 
  xml.XMLFormat := xfReadable; 
 
  //XML.FloatSignificantDigits := ; 
  with XML.Root.NodeNew('item') do begin 
    WriteString('Name', 'AAA'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  XML.FloatSignificantDigits := 5; 
  with XML.Root.NodeNew('item') do begin 
    WriteString('Name', 'BBB'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  XML.FloatSignificantDigits := 1; 
  with XML.Root.NodeNew('item') do begin 
    WriteString('Name', 'CCC'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  XML.FloatSignificantDigits := 9; 
  with XML.Root.NodeNew('item') do begin 
    WriteString('Name', 'DDD'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  ShowMessage(XML.Root[0][1].Value); //123.457 
  ShowMessage(XML.Root[1][1].Value); //123.46 
  ShowMessage(XML.Root[2][1].Value); //100 
  ShowMessage(XML.Root[3][1].Value); //123.456789 
  Memo1.Text := XML.WriteToString; 
  XML.Free; 
end; 
{*************************************** 
<?XML version="1.0" encoding="UTF-8"?> 
<List> 
 <item> 
 <Name>AAA</Name> 
 <Weight>123.457</Weight> 
 </item> 
 <item> 
 <Name>BBB</Name> 
 <Weight>123.46</Weight> 
 </item> 
 <item> 
 <Name>CCC</Name> 
 <Weight>100</Weight> 
 </item> 
 <item> 
 <Name>DDD</Name> 
 <Weight>123.456789</Weight> 
 </item> 
</List> 
*****************************************} 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved