No0ne Posted September 27, 2013 Report Share Posted September 27, 2013 Interesē, ar ko varētu panākt šādu konvertāciju: 1 => 0.01 10 => 0.10 100 => 1.00 1000 => 10.00 10000 => 100.00 Attiecīgi input - skaitlis, output ##.## ar 2 cipariem aiz punkta, attieciigi tie būs santīmi Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted September 27, 2013 Report Share Posted September 27, 2013 (edited) Javascriptā: (santimi/100).toFixed(2) C# ar visu Ls pie attiecīgas lokāles: string.Format("{0:C}", santimi / 100f); Edited September 27, 2013 by v3rb0 Quote Link to comment Share on other sites More sharing options...
No0ne Posted September 27, 2013 Author Report Share Posted September 27, 2013 un php versiju arī, lūdzu :) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted September 27, 2013 Report Share Posted September 27, 2013 round(x, 2) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted September 27, 2013 Report Share Posted September 27, 2013 What is Google, what is documentation... Quote Link to comment Share on other sites More sharing options...
php newbie Posted September 27, 2013 Report Share Posted September 27, 2013 parkonvertēt var izmantojot sarežģītu matemātisko operāciju Dalīšanu izvadīt vajadzīgaja formātā: http://php.net/manual/en/function.number-format.php Quote Link to comment Share on other sites More sharing options...
No0ne Posted September 27, 2013 Author Report Share Posted September 27, 2013 round(x, 2) Nepieciešams precīzs skaitlis, nevis noapaļots. Vai nākamreiz pirms sāc stāstīt par googli, vari iedot kādu strādājošu piemēru? number_format() un money_format() diezgan daudz visādas problēmas ir pieminētas, tāpēc gaidu no gudrākiem cilvēkiem info, kurš varētu būt labākais variants. Quote Link to comment Share on other sites More sharing options...
No0ne Posted September 27, 2013 Author Report Share Posted September 27, 2013 parkonvertēt var izmantojot sarežģītu matemātisko operāciju Dalīšanu izvadīt vajadzīgaja formātā: http://php.net/manual/en/function.number-format.php Vai arī kādu sarežģītu piemēru uzrakstīsi, kas darbojas visos gadījumos, kas ir topika sākumā? Quote Link to comment Share on other sites More sharing options...
Sasa Posted September 27, 2013 Report Share Posted September 27, 2013 Var .NET uzrakstīt bibliotēku ar šādu funkciju un tad caur php http://stackoverflow.com/questions/7874544/how-to-create-c-sharp-dll-to-use-in-php to izmantot. Quote Link to comment Share on other sites More sharing options...
codez Posted September 27, 2013 Report Share Posted September 27, 2013 http://codepad.org/tUAqr9Xj <?php $examples = array(1,10,100,1000,10000,12,123,2134,23452,2345234,25437648758); foreach($examples as $n){ echo $n." = ".number_format($n/100,2,".","'")."\n"; } Quote Link to comment Share on other sites More sharing options...
php newbie Posted September 27, 2013 Report Share Posted September 27, 2013 es godīgi nesaprotu kur problēma... codez apsteidza, bet nu jau uzrakstīju :)http://codepad.org/Nfo5otML Quote Link to comment Share on other sites More sharing options...
No0ne Posted September 27, 2013 Author Report Share Posted September 27, 2013 Liels paldies, codez un php newbie! Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted September 27, 2013 Report Share Posted September 27, 2013 Var .NET uzrakstīt bibliotēku ar šādu funkciju un tad caur php http://stackoverflow.com/questions/7874544/how-to-create-c-sharp-dll-to-use-in-php to izmantot. Just wow. Quote Link to comment Share on other sites More sharing options...
ieleja Posted September 27, 2013 Report Share Posted September 27, 2013 vēl jau var izmantot šo: http://www.mpfr.org/ lai izveidotu savu 'apache' moduli Quote Link to comment Share on other sites More sharing options...
daGrevis Posted September 27, 2013 Report Share Posted September 27, 2013 > Nepieciešams precīzs skaitlis, nevis noapaļots. Vai nākamreiz pirms sāc stāstīt par googli, vari iedot kādu strādājošu piemēru? Nedaudz neiedziļinājos šajā topikā. Tu man gribi pateikt, ka nezini, ka, dalot ar simts, tu iegūsi daiļskaitli? Piemērs: ~~~ ~ % php -r '$x = 12345; printf("%d.00", $x / 100);' 123.00% ~~~ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.