Hi, Some time ago I needed to export data as fixed length strings, including numbers (reals).
So I wrote this method: // Uty_FixLengthNum(rToConvert;lLength;lLengthDec;tFillChar;tDecSign;bAlwaysReturnDec) -> tFixLengthNum // ---------------------------------------------------- // User name (OS): Olivier // Date and time: 16.03.15, 16:00:49 // ---------------------------------------------------- // Method: Uty_FixLengthNum // Description // Converts a number (real) to a fixed length string // // Parameters: // $1, real, number to convert to a fixed lenght string // $2, longint, total lenght to fix // $3, longint, lenght of decimals to fix // $4, text, fill character, e.g. "0" (zero) // $5, text, decimal separator sign, e.g. "." // $6, boolean, if true, always return string with decimals, even if decimals are zero // if false, return numbers with zero decimal without decimals; // e.g. 100 is returned as 0000100 when $2 is 7, even if $3 is greater than zero // $0, text, number converted to a fixed length string // ---------------------------------------------------- ASSERT(Count parameters=6;"Not allowed number of parameter: "+String(Count parameters)) C_REAL($1;$rFixThis;$rInteger;$rDecimal) C_LONGINT($2;$3;$lFixMaxLenght;$lFixDecLenght;$lLenghtInt;$lLenghtDec;$lDifference;$lWhere) C_TEXT($4;$5;$0;$tFillChar;$tDecimalSeparator;$tResult;$tSystemDecimalSeparator;$tInt;$tDec) C_BOOLEAN($6;$bReturnZeroDecimals) $rFixThis:=$1 $lFixMaxLenght:=$2 $lFixDecLenght:=$3 $tFillChar:=$4 $tDecimalSeparator:=$5 $bReturnZeroDecimals:=$6 ASSERT((Length($tFillChar)=1);"Lenght of fill char is not exactly 1: "+$tFillChar) $tResult:=String($rFixThis) GET SYSTEM FORMAT(Decimal separator;$tSystemDecimalSeparator) $lWhere:=Position($tSystemDecimalSeparator;$tResult;*) If ($lWhere>0) $lDifference:=Length($tResult)-$lWhere $tInt:=Substring($tResult;1;$lWhere-1) $tDec:=Substring($tResult;$lWhere+1;$lDifference) $rInteger:=Num($tInt) $rDecimal:=Num($tDec) Else $tInt:=$tResult $tDec:="" $rInteger:=Num($tInt) $rDecimal:=Num($tDec) End if $lLenghtInt:=Length($tInt) $lLenghtDec:=Length($tDec) Case of : ($lFixMaxLenght<=0) $tResult:="" : (($rDecimal=0) & ($bReturnZeroDecimals=False) & ($lLenghtInt=$lFixMaxLenght)) $tResult:=$tInt : (($rDecimal=0) & ($bReturnZeroDecimals=False) & ($lLenghtInt<$lFixMaxLenght)) $lDifference:=($lFixMaxLenght-$lLenghtInt) If ($rInteger>=0) $tResult:=($tFillChar*$lDifference)+$tInt Else $tResult:="-"+($lDifference*$tFillChar)+String(Abs($rInteger)) End if : (($rDecimal=0) & ($bReturnZeroDecimals=False) & ($lLenghtInt>$lFixMaxLenght)) $tResult:="ERROR" Else Case of : ($lFixDecLenght<=0) & ($lLenghtInt=$lFixMaxLenght) $tResult:=$tInt : ($lFixDecLenght<=0) & ($lLenghtInt<$lFixMaxLenght) $lDifference:=$lFixMaxLenght-$lLenghtInt If ($rInteger>=0) $tResult:=($lDifference*$tFillChar)+$tInt Else $tResult:="-"+($lDifference*$tFillChar)+String(Abs($rInteger)) End if : ($lFixDecLenght<=0) & ($lLenghtInt>$lFixMaxLenght) $tResult:="ERROR" Else Case of : ($lLenghtDec>$lFixDecLenght) $tDec:=Substring($tDec;1;$lFixDecLenght) : ($lLenghtDec<$lFixDecLenght) $lDifference:=($lFixDecLenght-$lLenghtDec) $tDec:=$tDec+($lDifference*$tFillChar) End case $tResult:=$tInt+$tDecimalSeparator+$tDec Case of : (Length($tResult)<$lFixMaxLenght) $lDifference:=$lFixMaxLenght-(Length($tResult)) If ($rInteger>=0) $tResult:=($lDifference*$tFillChar)+$tResult Else $tResult:="-"+($lDifference*$tFillChar)+String(Abs($rInteger))+$tDecimalSeparator+$tDec End if : (Length($tResult)>$lFixMaxLenght) $tResult:="ERROR" End case End case End case $0:=$tResult // end of method This method is part of my utility methods component: https://flury-software.ch/a-swiss-army-knife-for-4d/ Best, Olivier -----Ursprüngliche Nachricht----- Von: 4D_Tech <4d_tech-boun...@lists.4d.com> Im Auftrag von 4dialog via 4D_Tech Gesendet: Mittwoch, 30. Januar 2019 08:42 An: 4d_tech@lists.4d.com Cc: 4dialog <helge.anton...@4dialog.no> Betreff: Re: XLS plugin - format number with leading zero Thanks for all answers. The problem is not i 4D, i get the leading zero but only in a text cell. In excel you can format manualy a column as number with fixed numbers preformated (selfdefined format). In my case, 11 numbers, "00000000000". If you put 10 numbers in a cell it gets leading zero. But is there a way to do this formating from 4d? ----- Hilsen -------------------------------------- Helge Antonsen www.4dialog.no -- Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html ********************************************************************** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com ********************************************************************** ********************************************************************** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **********************************************************************