@@ -533,12 +533,26 @@ func (f *sqlCmdFormatterType) scanRow(rows *sql.Rows) ([]string, error) {
533533 }
534534 case float64 :
535535 // Format float64 to match ODBC sqlcmd behavior
536- // Use 'f' format with -1 precision to avoid scientific notation
537- // and to show all significant digits
538- row [n ] = strconv .FormatFloat (x , 'f' , - 1 , 64 )
536+ // Use 'f' format with -1 precision to avoid scientific notation for typical values
537+ // Fall back to 'g' format if the result would exceed the column display width
538+ formatted := strconv .FormatFloat (x , 'f' , - 1 , 64 )
539+ displayWidth := f .columnDetails [n ].displayWidth
540+ if displayWidth > 0 && int64 (len (formatted )) > displayWidth {
541+ // Use 'g' format for very large/small values to avoid truncation issues
542+ formatted = strconv .FormatFloat (x , 'g' , - 1 , 64 )
543+ }
544+ row [n ] = formatted
539545 case float32 :
540546 // Format float32 to match ODBC sqlcmd behavior
541- row [n ] = strconv .FormatFloat (float64 (x ), 'f' , - 1 , 32 )
547+ // Use 'f' format with -1 precision to avoid scientific notation for typical values
548+ // Fall back to 'g' format if the result would exceed the column display width
549+ formatted := strconv .FormatFloat (float64 (x ), 'f' , - 1 , 32 )
550+ displayWidth := f .columnDetails [n ].displayWidth
551+ if displayWidth > 0 && int64 (len (formatted )) > displayWidth {
552+ // Use 'g' format for very large/small values to avoid truncation issues
553+ formatted = strconv .FormatFloat (float64 (x ), 'g' , - 1 , 32 )
554+ }
555+ row [n ] = formatted
542556 default :
543557 var err error
544558 if row [n ], err = fmt .Sprintf ("%v" , x ), nil ; err != nil {
0 commit comments