; DisplayFormats
; --------------
; Formatting lines
;
; Integer formats
; ---------------
; "IntCustom",        $sFmt [,$sNeg]
; "Int1000Sep",       $sSep
; "Int1000SepCustom", $sSep, $sFmt, $sNeg
;
; Floating point formats
; ----------------------
; "FltCustom",        $sFmt [,$sNeg]
; "Flt1000Sep",       $sSep, $sDec [,$iDec]
; "Flt1000SepCustom", $sSep, $sDec, $sFmt, $sNeg [,$iDec]
;
; Date formats
; ------------
; "DateDMY",          $sSep
; "DateMDY",          $sSep
; "DateYMD",          $sSep
;
; Time formats
; ------------
; "TimeHM"
; "TimeHMS"
;
;
; Names in quotation marks on the left are names of the formatting functions.
;
; $sFmt is a "format control" string as defined in AutoIt StringFormat() function.
; $sNeg is a "format control" string as defined in AutoIt StringFormat() function for negative numbers.
; If $sNeg is specified $sFmt is a "format control" string for non-negative numbers.
;
; $sSep is a 1-character 1000-separator in numbers and a 1-character date/month/year separator in dates.
; $sDec is a 1-character decimal point in floating point numbers.
;
; $iDec is the number of decimals in floating point numbers. Default is 2 decimals.
;
; HelpFiles\DisplayFormats.au3 can be used to test column formats.


; --- Integer formats ---

Func IntCustom( $iInt, $sFmt, $sNeg = "" )
	Return ( $sNeg ? StringFormat( ( $iInt < 0 ? $sNeg : $sFmt ), StringRegExpReplace( $iInt, "-?(\d+)", "\1" ) ) : StringFormat( $sFmt, $iInt ) )
EndFunc
ConsoleWrite( "IntCustom (1 par):" & @CRLF )
ConsoleWrite( IntCustom( 1000000, "%i" ) & @CRLF )
ConsoleWrite( IntCustom( -1000000, "%i" ) & @CRLF )
ConsoleWrite( IntCustom( 1000000, "%i kr." ) & @CRLF )
ConsoleWrite( IntCustom( -1000000, "%i kr." ) & @CRLF )
ConsoleWrite( @CRLF & "IntCustom (2 pars):" & @CRLF )
ConsoleWrite( IntCustom( 1000000, "$%i", "-$%i" ) & @CRLF )
ConsoleWrite( IntCustom( -1000000, "$%i", "-$%i" ) & @CRLF )
ConsoleWrite( IntCustom( 1000000, "$%i", "($%i)" ) & @CRLF )
ConsoleWrite( IntCustom( -1000000, "$%i", "($%i)" ) & @CRLF )
ConsoleWrite( IntCustom( 1000000, "%i kr.", "-%i kr." ) & @CRLF )
ConsoleWrite( IntCustom( -1000000, "%i kr.", "-%i kr." ) & @CRLF )
; IntCustom (1 par):
; 1000000
; -1000000
; 1000000 kr.
; -1000000 kr.
;
; IntCustom (2 pars):
; $1000000
; -$1000000
; $1000000
; ($1000000)
; 1000000 kr.
; -1000000 kr.

Func Int1000Sep( $iInt, $sSep )
	Return StringRegExpReplace( $iInt, "(\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))", "\1" & $sSep )
EndFunc
ConsoleWrite( @CRLF & "Int1000Sep:" & @CRLF )
ConsoleWrite( Int1000Sep( 1000000, "," ) & @CRLF )
ConsoleWrite( Int1000Sep( -1000000, "," ) & @CRLF )
; Int1000Sep:
; 1,000,000
; -1,000,000

Func Int1000SepCustom( $iInt, $sSep, $sFmt, $sNeg )
	Return StringFormat( ( $iInt < 0 ? $sNeg : $sFmt ), StringRegExpReplace( $iInt, "-?(\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))", "\1" & $sSep ) )
EndFunc
ConsoleWrite( @CRLF & "Int1000SepCustom:" & @CRLF )
ConsoleWrite( Int1000SepCustom( 1000000, ",", "$%s", "-$%s" ) & @CRLF )
ConsoleWrite( Int1000SepCustom( -1000000, ",", "$%s", "-$%s" ) & @CRLF )
ConsoleWrite( Int1000SepCustom( 1000000, ",", "$%s", "($%s)" ) & @CRLF )
ConsoleWrite( Int1000SepCustom( -1000000, ",", "$%s", "($%s)" ) & @CRLF )
ConsoleWrite( Int1000SepCustom( 1000000, ",", "%s kr.", "-%s kr." ) & @CRLF )
ConsoleWrite( Int1000SepCustom( -1000000, ",", "%s kr.", "-%s kr." ) & @CRLF )
; Int1000SepCustom:
; $1,000,000
; -$1,000,000
; $1,000,000
; ($1,000,000)
; 1,000,000 kr.
; -1,000,000 kr.

; --- Floating point formats ---

Func FltCustom( $fFlt, $sFmt, $sNeg = "" )
	Return ( $sNeg ? StringFormat( ( $fFlt < 0 ? $sNeg : $sFmt ), StringRegExpReplace( $fFlt, "-?(.+)", "\1" ) ) : StringFormat( $sFmt, $fFlt ) )
EndFunc
ConsoleWrite( @CRLF & "FltCustom (1 par):" & @CRLF )
ConsoleWrite( FltCustom( 1234567.123, "%.0f" ) & @CRLF )
ConsoleWrite( FltCustom( -1234567.123, "%.0f" ) & @CRLF )
ConsoleWrite( FltCustom( 1234567.123, "%.4f" ) & @CRLF )
ConsoleWrite( FltCustom( -1234567.123, "%.4f" ) & @CRLF )
ConsoleWrite( FltCustom( 1234567.123, "%.2f kr." ) & @CRLF )
ConsoleWrite( FltCustom( -1234567.123, "%.2f kr." ) & @CRLF )
ConsoleWrite( @CRLF & "FltCustom (2 pars):" & @CRLF )
ConsoleWrite( FltCustom( 1234567.123, "$%.2f", "-$%.2f" ) & @CRLF )
ConsoleWrite( FltCustom( -1234567.123, "$%.2f", "-$%.2f" ) & @CRLF )
ConsoleWrite( FltCustom( 1234567.123, "$%.2f", "($%.2f)" ) & @CRLF )
ConsoleWrite( FltCustom( -1234567.123, "$%.2f", "($%.2f)" ) & @CRLF )
ConsoleWrite( FltCustom( 1234567.123, "%.2f kr.", "-%.2f kr." ) & @CRLF )
ConsoleWrite( FltCustom( -1234567.123, "%.2f kr.", "-%.2f kr." ) & @CRLF )
; FltCustom (1 par):
; 1234567
; -1234567
; 1234567.1230
; -1234567.1230
; 1234567.12 kr.
; -1234567.12 kr.
;
; FltCustom (2 pars):
; $1234567.12
; -$1234567.12
; $1234567.12
; ($1234567.12)
; 1234567.12 kr.
; -1234567.12 kr.

Func Flt1000Sep( $fFlt, $sSep, $sDec, $iDec = 2 )
	Local $a = StringRegExp( StringFormat( "%." & ( $iDec ? $iDec : 2 ) & "f", $fFlt ), "(-?\d+)\.(\d+)$", 1 )
	Return StringRegExpReplace( $a[0], "(\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))", "\1" & $sSep ) & $sDec & $a[1]
EndFunc
ConsoleWrite( @CRLF & "Flt1000Sep:" & @CRLF )
ConsoleWrite( Flt1000Sep( 1234567.123, ",", "." ) & @CRLF )
ConsoleWrite( Flt1000Sep( -1234567.123, ",", "." ) & @CRLF )
ConsoleWrite( Flt1000Sep( 1234567.123, ",", ".", 4 ) & @CRLF )
ConsoleWrite( Flt1000Sep( -1234567.123, ",", ".", 4 ) & @CRLF )
; Flt1000Sep:
; 1,234,567.12
; -1,234,567.12
; 1,234,567.1230
; -1,234,567.1230

Func Flt1000SepCustom( $fFlt, $sSep, $sDec, $sFmt, $sNeg, $iDec = 2 )
	Local $a = StringRegExp( StringFormat( "%." & ( $iDec ? $iDec : 2 ) & "f", $fFlt ), "(\d+)\.(\d+)$", 1 )
	Return StringFormat( ( $fFlt < 0 ? $sNeg : $sFmt ), StringRegExpReplace( $a[0], "-?(\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))", "\1" & $sSep ) & $sDec & $a[1] )
EndFunc
ConsoleWrite( @CRLF & "Flt1000SepCustom:" & @CRLF )
ConsoleWrite( Flt1000SepCustom( 1234567.123, ",", ".", "$%s", "-$%s" ) & @CRLF )
ConsoleWrite( Flt1000SepCustom( -1234567.123, ",", ".", "$%s", "-$%s" ) & @CRLF )
ConsoleWrite( Flt1000SepCustom( 1234567.123, ",", ".", "$%s", "($%s)" ) & @CRLF )
ConsoleWrite( Flt1000SepCustom( -1234567.123, ",", ".", "$%s", "($%s)" ) & @CRLF )
ConsoleWrite( Flt1000SepCustom( 1234567.123, ",", ".", "%s kr.", "-%s kr." ) & @CRLF )
ConsoleWrite( Flt1000SepCustom( -1234567.123, ",", ".", "%s kr.", "-%s kr." ) & @CRLF )
; Flt1000SepCustom:
; $1,234,567.12
; -$1,234,567.12
; $1,234,567.12
; ($1,234,567.12)
; 1,234,567.12 kr.
; -1,234,567.12 kr.

; --- Date formats ---

Func DateDMY( $iYMD, $sSep )
	Local $a = StringRegExp( "0000" & $iYMD, "(\d\d\d\d)(\d\d)(\d\d)$", 1 )
	Return $a[2] & $sSep & $a[1] & $sSep & $a[0]
EndFunc
ConsoleWrite( @CRLF & "Dates:" & @CRLF )
ConsoleWrite( DateDMY( 20170915, "-" ) & @CRLF )
; 15-09-2017

Func DateMDY( $iYMD, $sSep )
	Local $a = StringRegExp( "0000" & $iYMD, "(\d\d\d\d)(\d\d)(\d\d)$", 1 )
	Return $a[1] & $sSep & $a[2] & $sSep & $a[0]
EndFunc
ConsoleWrite( DateMDY( 20170915, "-" ) & @CRLF )
; 09-15-2017

Func DateYMD( $iYMD, $sSep )
	Local $a = StringRegExp( "0000" & $iYMD, "(\d\d\d\d)(\d\d)(\d\d)$", 1 )
	Return $a[0] & $sSep & $a[1] & $sSep & $a[2]
EndFunc
ConsoleWrite( DateYMD( 20170915, "-" ) & @CRLF )
; 2017-09-15

; --- Time formats ---

Func TimeHM( $iHMS )
	Local $a = StringRegExp( "00000" & $iHMS, "(\d\d)(\d\d)(\d\d)$", 1 )
	Return $a[0] & ":" & $a[1]
EndFunc
ConsoleWrite( @CRLF & "Times:" & @CRLF )
ConsoleWrite( TimeHM( 183000 ) & @CRLF )
; 18:30

Func TimeHMS( $iHMS )
	Local $a = StringRegExp( "00000" & $iHMS, "(\d\d)(\d\d)(\d\d)$", 1 )
	Return $a[0] & ":" & $a[1] & ":" & $a[2]
EndFunc
ConsoleWrite( TimeHMS( 183000 ) & @CRLF )
; 18:30:00
