printf

Stm32 printf float variable

独自空忆成欢 提交于 2020-12-03 07:39:59
问题 I want to log out from stm32f405 via usart. In my syscall.c file i realize function to print via usart: int _write(int file, char *ptr, int len) { int todo; for (todo = 0; todo < len; todo++) { usart_send_char( *ptr++ ); } return len; } Function usart_send_char( *ptr++ ); work as expected. But when i call: printf("%s, %d, %3.2f\r\n", "asd", 777, 13.2 ); I get: asd, 777, 0.00 The float variable not printed correctly. Makefile: PROCESSOR = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4

Stm32 printf float variable

百般思念 提交于 2020-12-03 07:36:06
问题 I want to log out from stm32f405 via usart. In my syscall.c file i realize function to print via usart: int _write(int file, char *ptr, int len) { int todo; for (todo = 0; todo < len; todo++) { usart_send_char( *ptr++ ); } return len; } Function usart_send_char( *ptr++ ); work as expected. But when i call: printf("%s, %d, %3.2f\r\n", "asd", 777, 13.2 ); I get: asd, 777, 0.00 The float variable not printed correctly. Makefile: PROCESSOR = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4

Stm32 printf float variable

这一生的挚爱 提交于 2020-12-03 07:35:20
问题 I want to log out from stm32f405 via usart. In my syscall.c file i realize function to print via usart: int _write(int file, char *ptr, int len) { int todo; for (todo = 0; todo < len; todo++) { usart_send_char( *ptr++ ); } return len; } Function usart_send_char( *ptr++ ); work as expected. But when i call: printf("%s, %d, %3.2f\r\n", "asd", 777, 13.2 ); I get: asd, 777, 0.00 The float variable not printed correctly. Makefile: PROCESSOR = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4

Rounding floating number using AWK

ぃ、小莉子 提交于 2020-11-29 05:01:30
问题 I have a file b.xyz as, -19.794325 -23.350704 -9.552335 -20.313872 -23.948248 -8.924463 -18.810708 -23.571757 -9.494047 -20.048543 -23.660052 -10.478968 I want to limit each of the entries to three decimal digits. I tried this one awk '{ $1=sprintf("%.3f",$1)} {$2=sprintf("%.3f",$2)} {$3=sprintf("%.3f",$3)} {print $1, $2, $3}' b.xyz it works for three columns, but how to expand it to apply for n/all columns? 回答1: If you will always have three fields, then you can use: $ awk '{printf "%.3f %

Rounding floating number using AWK

本小妞迷上赌 提交于 2020-11-29 05:01:27
问题 I have a file b.xyz as, -19.794325 -23.350704 -9.552335 -20.313872 -23.948248 -8.924463 -18.810708 -23.571757 -9.494047 -20.048543 -23.660052 -10.478968 I want to limit each of the entries to three decimal digits. I tried this one awk '{ $1=sprintf("%.3f",$1)} {$2=sprintf("%.3f",$2)} {$3=sprintf("%.3f",$3)} {print $1, $2, $3}' b.xyz it works for three columns, but how to expand it to apply for n/all columns? 回答1: If you will always have three fields, then you can use: $ awk '{printf "%.3f %

Rounding floating number using AWK

丶灬走出姿态 提交于 2020-11-29 05:01:05
问题 I have a file b.xyz as, -19.794325 -23.350704 -9.552335 -20.313872 -23.948248 -8.924463 -18.810708 -23.571757 -9.494047 -20.048543 -23.660052 -10.478968 I want to limit each of the entries to three decimal digits. I tried this one awk '{ $1=sprintf("%.3f",$1)} {$2=sprintf("%.3f",$2)} {$3=sprintf("%.3f",$3)} {print $1, $2, $3}' b.xyz it works for three columns, but how to expand it to apply for n/all columns? 回答1: If you will always have three fields, then you can use: $ awk '{printf "%.3f %