xref: /openbmc/u-boot/lib/strmhz.c (revision e8f80a5a)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2002-2006
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6 #include <common.h>
7 
strmhz(char * buf,unsigned long hz)8 char *strmhz (char *buf, unsigned long hz)
9 {
10 	long l, n;
11 	long m;
12 
13 	n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L;
14 	l = sprintf (buf, "%ld", n);
15 
16 	hz -= n * 1000000L;
17 	m = DIV_ROUND_CLOSEST(hz, 1000L);
18 	if (m != 0)
19 		sprintf (buf + l, ".%03ld", m);
20 	return (buf);
21 }
22