Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

ZTrim( N := "" ) { ; SKAN / CD:01-Jul-2017 | LM:03-Jul-2017 | Topic: goo.gl/TgWDb5

Local V := StrSplit( N, ".", A_Space )

Local V0 := SubStr( V.1,1,1 ), V1 := Abs( V.1 ), V2 := RTrim( V.2, "0" )

Return ( V0 = "-" ? "-" : "" ) ( V1 = "" ? 0 : V1 ) ( V2 <> "" ? "." V2 : "" )

}

;---------------------------------------------------------------------------------

; Example:

MsgBox % ( A := 1.234000 ) "`t=`t" ZTrim( A ) "`n"

. ( A := 00.00100 ) "`t=`t" ZTrim( A ) "`n"

. ( A := -123.010 ) "`t=`t" ZTrim( A ) "`n"

. ( A := -.212 ) "`t=`t" ZTrim( A ) "`n"

. ( A := "+001. 100" ) "`t=`t" ZTrim( A ) "`n"

. ( A := "1 .12300 " ) "`t=`t" ZTrim( A ) "`n"

. ( A := 100.00 ) "`t=`t" ZTrim( A ) "`n"

. ( A := 100 ) "`t=`t" ZTrim( A ) "`n"