xLang 的类型转换

xLang 的类型转换

今天学习了xLang 的类型转换

1、如果想要把 Int 转换为 String,可以使用 String.format("%d", 123)

例如

int a = 2;
string b = "";
b = String.format("%d", a);

这里的 %d 部分,可以替换成其他(列举常用的):

%d 整数   
%f 浮点数,默认保留6位小数点
%s 字符串
%c 字符
%.[n]f 是保留n位小数点
%e 是格式化浮点数为科学计数法
%[n]d 格式化整数,n是保留几位整数,例如 format("%02d", 1)  就是 "01"
%g 是格式化浮点数
%s 是格式化字符串
%X是格式化为十六进制数
%p 是格式化指针  用的很少
String.formatDate 用于格式化日期

%d 和 %[n]d
在这里插入图片描述
在这里插入图片描述
%c 是格式化字符
在这里插入图片描述
%f 是格式化浮点数,默认保留6位小数点
在这里插入图片描述
在这里插入图片描述
%e 是格式化浮点数为科学计数法
在这里插入图片描述
%p 是格式化指针 用的很少
在这里插入图片描述
String.formatDate 格式化代码

/**
	*@brief 格式化日期字符串
	*@param fmt 格式 %Y年 %m月 %d日 %H时 %M分 %S 秒 可用格式如下
    *       a:  abbreviated weekday name 
    *       A:  full name of the weekday 
    *       b:  abbreviated month name 
    *       B:  full name of month 
    *       c:  locale's date and time reprensentation 
    *       d:  day of the month (01-31) 
    *       H:  hour of the day (00-23) 
    *       I:  hour of the day (01-12) 
    *       j:  day of the year (001-366)
    *       m:  month of the year (01-12)
    *       M:  minute (00-59)
    *       p:  locale's version of AM or PM
    *       S:  seconds (00-59)
    *       U:  week number of the year (00-53) with Sunday as the first day of the week
    *       w:  weekday (Sunday = 0 to Saturday = 6)
    *       W:  week number of the year (00-53) with Monday as the first day of the week
    *       x:  locale's date representation 
    *       X:  locale's time representation
    *       y:  two-digit year representation (00-99)
    *       Y:  four-digit year representation
    *       Z:  time zone name
    *@millis 毫秒数
	*@return 格式化结果
	*/
	static String formatDate(String fmt, long millis);

在这里插入图片描述

在这里插入图片描述

2、如果想把 String 转换成 Int ,可以使用 parseInt()

例如

string a = "1234";
string b = "7890";
string c = a + b;
int d = c.parseInt();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值