Dugan
Dugan

Reputation: 117

Adding variable numbers of 0's

I have a set of locations with the following naming convention:

I want to change all of the KP values so that there are 3 digits before the decimal place, e.g.:

Can anyone think of a way to do this that doesn't involve 10 nested substitute functions?

Upvotes: 0

Views: 35

Answers (2)

John Coleman
John Coleman

Reputation: 51998

If Your strings are in A1:A3, enter this in B1 and copy down:

=LEFT(A1,3) & REPT("0",7 - FIND(".",A1)) & RIGHT(A1,LEN(A1)- 3)

enter image description here

Upvotes: 3

user4039065
user4039065

Reputation:

Try,

=TRIM(LEFT(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1))&TEXT(VALUE(MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1),LEN(A1)))," 000.0# ")&MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1)*2,LEN(A1))&MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1)*3,LEN(A1)))

enter image description here

Upvotes: 1

Related Questions