Msphpsql: `sqlsrv` omits leading zeros for decimal/float values

Created on 14 Nov 2018  路  4Comments  路  Source: microsoft/msphpsql

## PHP Driver version or file name

sqlsrv 5.3.0 PECL

## SQL Server version

SQL Server 2016 Standard

## Client operating system

Ubuntu LTS 18.04

## PHP version

PHP 7.2 - From official Ubuntu 18.04 repositories

Microsoft ODBC Driver version

msodbcsql17/bionic,now 17.2.0.1-1 amd64 (MD5sum: 0a13d93b2af7a0383f93d71448feb0a4)

Problem description

We upgraded from the deprecated mssql PHP driver to sqlsrv. Our application is written in PHP + Symfony and uses Doctrine to communicate to SQL Server. The platform we are on is Ubuntu 18.04 (after upgrading). Everything works, except for zero decimal/float values. The issue is that the sqlsrv driver omits leading zeros. Values which are in the dabase 0.00 will be fetched as .00.

Actual behavior

sqlsrv driver omits leading zeros in front of decimal/float values.

For example:

  • In the database: 0.00.
  • After retrieving the value: .00 in PHP application.

Expected behavior

sqlsrv driver does not omit leading zeros.

Float/decimal values should be returned with leading zeros.

For example:

  • In the database: 0.00.
  • After retrieving the value: 0.00 in PHP application.

Related

Driver omitting leading zero in decimal

by design

All 4 comments

Hello @Jeeppler

This is by design and related to a feature request discussed in #415.

New configuration options to format outputs for decimal and numeric for both sqlsrv and pdo_sqlsrv have been recently implemented. Please stay tuned for the release of our next preview to try this out.

@yitam are you referring to this pull request: https://github.com/Microsoft/msphpsql/pull/861 ?

@Jeeppler we merged two pull requests (#861 and #873). The changes only applied to decimal and/or numeric types because they are always fetched as strings, unlike floats or integers, which can be fetched as numbers.

@Jeeppler closing this issue as it is closely related to #415

Was this page helpful?
0 / 5 - 0 ratings