# Round an integer to the two leading digits with trailing zeroes?

Posted 11 days ago
138 Views
|
6 Replies
|
1 Total Likes
|
 56789012 -> 57000000, for example. Thanks for any help.
6 Replies
Sort By:
Posted 10 days ago
 rnd[n_] := Block[{d = 10^(Floor[Log[10, n]] - 1)}, d*Round[n/d]] rnd[56789012] 57000000 
Posted 10 days ago
 In[1]:= rnd[n_] := Round[n, 10^(Floor[Log[10, n]] - 1)] In[2]:= rnd[56789012] Out[2]= 57000000 
Posted 10 days ago
 The function Round could be used right out of the box. Documentation. In[1]:= Round[56789012, 10^6] Out[1]= 57000000 
Posted 10 days ago
 the second argument depends on the size of the number being rounded
 Frank, you are right. The second argument of Round "out of the box" starts from the decimal point. But the OP wants a rounding starting from the leading digit. Which your function does.