Scanf.scanf "%d" (fun n -> let rec loop r acc = if r < 1000 then Printf.sprintf "%d%s" r acc else loop (r / 1000) (Printf.sprintf ",%03d%s" (r mod 1000) acc) in loop n "" |> print_endline )