Java/値の編集
jshell> "%sと%s".formatted("test", "sample")
$1 ==> "testとsample"
jshell> "金額%,d円".formatted(1000)
$2 ==> "金額1,000円"
"1.24".matches("(0|[1-9][0-9]*)(\\.[0-9]+)?");
Pattern pat = Pattern.compile("(0|[1-9][0-9]*)(\\.[0-9]+)?");
pat.matcher("1.24").matches();
小数部を正確に扱うには、valueOfメソッドでdouble型を渡すか、newでString型を渡すとよい。
jshell> var b579 = BigDecimal.valueOf(579)
b579 ==> 579
jshell> b579.multiply(new BigDecimal("5"))
$2 ==> 2895
jshell> new BigDecimal(0.05)
$3 ==> 0.05000000000000000277555756156289135105907917022705078125
jshell> BigDecimal.valueOf(0.05)
$4 ==> 0.05
jshell> import java.time.*
jshell> LocalDate.now()
$2 ==> 2022-03-27
jshell> LocalTime.now()
$3 ==> 18:15:06.908445300
jshell> LocalDateTime.now()
$4 ==> 2022-03-27T18:15:15.981095300
jshell> LocalDate.of(2016, 9, 23)
$5 ==> 2016-09-23
jshell> "%tY年%<tm月%<td日".formatted(LocalDateTime.now())
$6 ==> "2022年04月02日"
jshell> var formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy年M月d日")
formatter ==> Value(YearOfEra,4,19,EXCEEDS_PAD)'年'Value(MonthOfYear)'月'Value(DayOfMonth)'日'
jshell> formatter.format(LocalDate.of(2016, 9, 23))
$8 ==> "2016年9月23日"
jshell> formatter.parse("2022年4月2日")
$9 ==> {},ISO resolved to 2022-04-02
jshell> LocalDateTime.now().plusDays(3)
$10 ==> 2022-03-30T18:16:14.430096300