【セル型】 小数桁の書式設定をしたい

文書番号 : 21813     文書種別 : 使用方法     最終更新日 : 2006/06/23
文書を印刷する
対象製品
SPREAD for .NET 2.5J Web Forms Edition
詳細
DoubleCellTypeクラスのNumberFormatInfoプロパティを使用します。
下記のサンプルコードでは整数部分を3桁区切りで表示し、小数点以下桁数を2桁に設定します。

[サンプルコード]

●VBサンプルコード
Imports FarPoint.Web.Spread
Imports System.Globalization
     :
  '倍精度型セルの設定
  Dim db As New DoubleCellType
  Dim ninfo As NumberFormatInfo = CType(CultureInfo.CurrentCulture.NumberFormat.Clone(),NumberFormatInfo)
  ninfo.NumberDecimalDigits=2 '小数点以下2桁まで表示
  ninfo.NumberGroupSizes = New Int32(){3} '整数部は3桁区切り
  db.NumberFormat=ninfo

  'セル型を1列目に設定
  FpSpread1.Sheets(0).Columns(0).CellType = db
  FpSpread1.Sheets(0).Cells(0,0).Value=9999.123 'A1セル
  FpSpread1.Sheets(0).Cells(1,0).Value=9999.0 'A2セル


●C#サンプルコード
using FarPoint.Web.Spread;
using System.Globalization;
     :
  //倍精度型セルの設定
  DoubleCellType db=new DoubleCellType();
  NumberFormatInfo ninfo=(NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone();
  ninfo.NumberDecimalDigits=2;//小数点以下2桁まで表示
  ninfo.NumberGroupSizes=new Int32[]{3};//整数部は3桁区切り
  db.NumberFormat=ninfo;

  //セル型を1列目に設定
  FpSpread1.Sheets[0].Columns[0].CellType=db;
  FpSpread1.Sheets[0].Cells[0,0].Value=9999.123;//A1セル
  FpSpread1.Sheets[0].Cells[1,0].Value=9999.0;//A2セル


[実行時に表示される値]

A1セル・・・「9,999.12」と表示されます。
A2セル・・・「9,999.00」と表示されます。
関連情報
キーワード
クライアント側スクリプト セル型 一般

この文書は、以前は次のFAQ IDで公開されていました : 9137