Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert php to 6 decimal places

Shulou Source: shulou.com Published: 2022-06-01 03:05:47 10月02日 Update

This article mainly shows you "how to convert php into 6 decimal places". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to convert php into 6 decimal places".

Conversion methods: 1, the use of "round (value, 6)" logarithm rounding conversion to 6 decimal places; 2, the use of "sprintf (% .6f", value) "format value into 6 decimal places; 3, the use of" number_format (value, 6) "thousand-place grouping format value into 6 decimal places.

This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.

How to convert php to 6 decimal places

1. Use the round () function.

The round () function rounds floating-point numbers.

Grammar

Round (number,precision,mode)

Number is required. Specifies the value to round.

Precision is optional. Specify the Mantissa after the decimal point. The default is 0, or it can be negative.

Mode is optional. Specifies the constant that represents the rounding mode:

2. Use the sprintf () function.

The sprintf () function writes the formatted string to a variable.

The arg1, arg2, + + parameters are inserted at the percent sign (%) symbol in the main string. This function is executed step by step. At the first% symbol, insert arg1, at the second% symbol, insert arg2, and so on.

Grammar

Sprintf (format,arg1,arg2,arg++)

Format is required. Specifies the string and how to format the variables in it.

3. Use the number_format () function.

The number_format () function formats numbers by grouping thousands of bits.

This function supports one, two, or four parameters (not three).

Grammar

Number_format (number,decimals,decimalpoint,separator)

Examples are as follows

Output result:

These are all the contents of the article "how to convert php to 6 decimal places". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Functions decimals formats numeric values characters strings rounding content symbols articles grammar rounding grouping parameters variables numbers points learning help and so on Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Linux Apple Huawei Docker