


Conversion of various formats of js string ToString, Format_javascript skills
If we all calculate the correct format and then display it, it will obviously be a waste of code and efficiency. Today I saw many formats that ToString can solve. I will summarize them for everyone, hoping it can be convenient for everyone.
1. Convert money format, only int type, float type, double type
double d = 400;
d.ToString("C"); //¥400.00
2.10 decimal Numbers, only int type numbers
int i=400;
i.ToString("D5"); // 00400
3. Scientific numbers, only int type, float type, double type
float f = 400;
f.ToString("E");//4.000000E 002
4. Fixed format numbers, only int type, float type, double type
int i =400;
i.ToString("F3");//400.000 Fn represents n digits after the decimal point, F2 and F represent 2 digits after the decimal point
5.N numeric type
400000000000.ToString("N ")// 400,000,000,000.00" N will convert the number to oh digits after the decimal point, and there will be one every 3 digits.
The difference between it and C is that there is no preceding ¥ symbol
6.16 hexadecimal
400000000000. ToString("x")//"5d21dba000" Convert numbers to hexadecimal numbers
================== Date format conversion====== ==============
Date format In addition to the classes already encapsulated by Datetime, you can also use string .Format(); to convert to a specified format
string .Format("{0:f}",System.DateTime.Now);//Thursday, August 4, 2011 11:23
string.Format("{0:F}", System.DateTime.Now );//Thursday, August 4, 2011 11:23:53
dt.GetDateTimeFormats('s')[0].ToString();//2005-11-05T14:06:25
dt .GetDateTimeFormats('t')[0].ToString();//14:06
dt.GetDateTimeFormats('y')[0].ToString();//November 2005
dt. GetDateTimeFormats('D')[0].ToString();//November 5, 2005
dt.GetDateTimeFormats('D')[1].ToString();//2005 11 05
dt .GetDateTimeFormats('D')[2].ToString();//Saturday 2005 11 05
dt.GetDateTimeFormats('D')[3].ToString();//Saturday November 5, 2005
dt.GetDateTimeFormats('M')[0].ToString();//November 5
dt.GetDateTimeFormats('f')[0].ToString();//November 5, 2005 Day 14:06
dt.GetDateTimeFormats('g')[0].ToString();//2005-11-5 14:06
dt.GetDateTimeFormats('r')[0].ToString( );//Sat, 05 Nov 2005 14:06:25 GMT
string.Format("{0:d}",dt);//2005-11-5
string.Format( "{0:D}",dt);//November 5, 2005
string.Format("{0:f}",dt);//November 5, 2005 14:23
string.Format("{0:F}",dt);//November 5, 2005 14:23:23
string.Format("{0:g}",dt);//2005 -11-5 14:23
string.Format("{0:G}",dt);//2005-11-5 14:23:23
string.Format("{0:M} ",dt);//November 5
string.Format("{0:R}",dt);//Sat, 05 Nov 2005 14:23:23 GMT
string.Format(" {0:s}",dt);//2005-11-05T14:23:23
string.Format("{0:t}",dt);//14:23
string.Format ("{0:T}",dt);//14:23:23
string.Format("{0:u}",dt);//2005-11-05 14:23:23Z
string.Format("{0:U}",dt);//November 5, 2005 6:23:23
string.Format("{0:Y}",dt);// November 2005
string.Format("{0}",dt);//2005-11-5 14:23:23
string.Format("{0:yyyyMMddHHmmssffff}", System.DateTime.Now);
yyyy represents the year MM represents the month dd represents the day HH represents the hour mm represents the minute ss represents the second ffff represents the second with 4 decimal places
Write so much for now, if I will continue to modify it if I find anything in the future.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This article will explain in detail how to format a GMT/UTC date/time with PHP. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Introduction to Formatting GMT/UTC Date/Time in PHP In PHP, formatting GMT/UTC date/time is crucial for correctly displaying and handling cross-time zone dates. This article will explain how to format a GMT/UTC date/time using PHP's DateTime class, as well as the various formatting options available. DateTime class The DateTime class represents a date and time. It can store and manipulate date/time values in time zones such as GMT/UTC. To create a new Da

Convert a StringBuffer to a string using the toString() method of the StringBuffer class. In Java, the StringBuffer class is a class used to handle mutable strings. It provides many convenient methods to modify and manipulate strings. When we need to convert a StringBuffer object into a string, we can use the toString() method to achieve this. The toString() method of the StringBuffer class returns a

format in Python is a string formatting method used to insert variables or values into placeholder positions in a string. Through the format method, we can dynamically construct a string to contain different values.

The usage of format in python is basic usage, specifying location, specifying variable name, formatting numbers, formatting date and time.

In Python, `format` is a built-in function used to format strings. It is used to create a string template with placeholders and fill the placeholders with specified values. This allows strings to be constructed dynamically based on different situations, making the output more readable and customizable.

STR_TO_DATE(date, format): Convert the string into the date and time in format SELECTSTR_TO_DATE(‘2015-01-01’,‘%Y-%m-%d’)->2015-01-01

Method of inserting variables into a string The format() function in Python is a method of inserting variables into a string, which can make the string easier to read and understand. It supports many different usages. The following are specific usages and instructions: Use positional parameters to pass variables name='John'age=25print('Mynameis{},andIam{}yearsold.'.format(name,age))#output :MynameisJohn,andIam25yearsold. Use the index to pass the variable name='

Simulate the implementation of the tostring function publicstaticStringmyToString(int[]array){Stringstr="[";for(inti=0;i
